Possible Duplicates:
How to get index of <li> element
jQuery - get the index of a element with a certain class
I have:
<ul id="parent"> <li id="li1">li1</li> <li id="li2">li2</li> <li id="li3">li3</li> </ul>
There are some other <ul>
and <li>
tags elsewhere.
I want to get the index of li2 which is in the <ul>
with id parent using jQuery
In JavaScript, you can use the . getElementsByTagName() method to get all the <li> elements in <ul>. In-addition, you can use the . querySelectorAll() method also to get all the <li>.
Answer: yes it does, but with: ol or menu, that's all!
ready(function() { $('#list li'). click(function() { alert($(this). attr("id")); alert($(this). text()); }); });
OLD simple answer: $('ul#parent li:eq(1)').index()
NEW $('#li2').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