Thomas Leu
Thomas Leu

Reputation: 855

jQuery .index() returns wrong number

So I had this problem where the jQuery .index() method returned a wrong index, more precisely the correct index + 1. It's not like there was an invisible element that I'm not aware of, as the following line gives me a 'false'.

alert(element.parent().find('.user').get(element.index('.user')) == element[0]);

Note that element is a jQuery object. I thought this line should by definition always alert 'true'. Did I just misinterpret the definition of the method find or why would this be the case?

Upvotes: 1

Views: 670

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388436

From what I can see what you are looking for is

var index = element.parent().find('.user').index(element);

Upvotes: 2

Related Questions