Search code examples
jquerychaining

Chaining the jQuery index() function


I have the following code:

var td = textbox.closest('tr').children('td:first');

I want to get the index of the closest tr withind a table and set it to a variable so I'd need to put the index() function bewteen closest('tr') and children('td:first');. Something like this:

var td = textbox.closest('tr').index(/*PUT A FUNCTION HERE */).children('td:first');

I know I can accomplish this just like this way:

var index = textbox.closest('tr').index();

but I was wondering whether is possible to make it using chaining method.


Solution

  • The index function returns a number, not a jQuery object. You can't chain it.