Chaining functions in jQuery. I cannot find an explanation anywhere.

Posted by Marius on Stack Overflow See other posts from Stack Overflow or by Marius
Published on 2010-03-29T23:28:51Z Indexed on 2010/03/29 23:33 UTC
Read the original article Hit count: 382

Filed under:
|
|
|
|

Hello there,

I have no idea how to do this.

My markup:

<table>
    <tr>
        <td id="colLeft">
            Lorem ipsum dolor<br/>
            Lorem ipsum dolor<br/>
            Lorem ipsum dolor<br/>
            Lorem ipsum dolor<br/>
            Lorem ipsum dolor<br/>
            Lorem ipsum dolor.
        </td>
        <td id="colRight">
            <div>1</div>
            <div>2</div>
        </td>
    </tr>
</table>

$(document).ready(function() {
    $('#colRight > div').each(function() { // I try to: select all divs in #colRight
        $(this).height(function(){ // I try to: sets the height of each div to:
            $('#colLeft').height() / $('#colRight > div').length(); // the height of #colLeft divided by the number of divs in colRight.  
        });
    });     
});

What I am trying to do is to change the height of each div to the height of #colLeft divided by the number of divs in #colRight.

However, it doesnt work.

I've never understood how to chain functions, and never found anyone to teach me.

So I would like to ask two favours of you.

  1. Why doesnt my above jQuery code.
  2. Does anyone know of a tutorial that explains it more detailed than in the tutorials on the jQuery website?

Thank you for your time.

Kind regards,
Marius

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about callback