0
By default jQuery always returns the highest index when the selector returns more than one element, as in the example below:
<ul>
<li>1</li>
<li>2</li>
<li class="error">3</li>
</ul>
<ul>
<li class="error">4</li>
<li>5</li>
<li>6</li>
</ul>
$('li').click(function(){
alert($('.error').parents('ul').index());
})
I tried that way too:
alert($('.error')[0].parents('ul').index());
However, this instruction returns:
Typeerror: Undefined is not a Function
What you want to return?
– stderr
The lowest index value
– Iago Leão
Tried $('. error'). Closest('ul'). index(); ? But from what I saw, what you get is index(), are das li, in your case it would be $(this). index()...
– Rafael Withoeft
or $('.error'). Closest('ul'). find('li:first'). index(); NOTE: I have not tested
– Rafael Withoeft
I don’t know if that’s what you want, but try:
$('.error').eq(0).parent().index()
– Lucas
Have you solved the problem? I still don’t understand what you want.
– bfavaretto