<ul>
<li>Kelvin</li>
<li>Jerry</li>
<li>Adi</li>
<li>Dani</li>
<li>Olvin</li>
</ul>
How to get the index of the <li> element that contains "Jerry"?
I've tried to read these
But can't find the answer :( Can you help me with that?
<ul>
<li>Kelvin</li>
<li>Jerry</li>
<li>Adi</li>
<li>Dani</li>
<li>Olvin</li>
</ul>
How to get the index of the <li> element that contains "Jerry"?
I've tried to read these
But can't find the answer :( Can you help me with that?
Using jQuery's .index will give you the index of an element in the given elements:
var index = $('li').index($('li:contains("Jerry")'));
Somewhat more efficiently:
var jerry = $('li:contains("Jerry")');
var jerry_index = jerry.siblings().index(jerry);
jerry.parent().children().index(jerry); though, since .index works on a set of elements.