Reputation: 2156
I'm refactoring the following code:
$(this).parent().find('td').index(this)
into this code:
$(this).siblings('td').index(this)
which baslically searches among the TDs of the current TR by accessing sibling TDs rather than going up to the TR and down again to the TDs.
But where the first code returns 19
, which is correct, the second returns -1
, which obviously isn't.
I'm puzzled...
Upvotes: 0
Views: 98
Reputation: 2156
Got it!
$(this).siblings('td').addBack().index(this)
Siblings are actually all other TDs, so I have to include the current TD as well!
Upvotes: 1
Reputation: 92943
I believe what you wanted is:
$(this).siblings('td').addBack().index(this)
Upvotes: 3