I have a simple unordered list and would like to find the numeric index/position of a specific element.
e.g:
<ul id="mylist">
<li id="id_a">Content</li>
<li id="id_b">Content</li>
<li id="id_c">Content</li>
<li id="id_d">Content</li>
<li id="id_e">Content</li>
</ul>
Pseudo code:
$('ul#mylist').getNumericIndexOf('id_c'); // 2
$('ul#mylist').getNumericIndexOf('id_a'); // 0
$('ul#mylist').getNumericIndexOf('id_e'); // 4
Any input is much appreciated!
Use index()
:
DEMO
$("#id_c").index();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With