I have a list of an indeterminate number of child elements:
<ul>
<li ID="alpha"></li>
<li ID="bravo"></li>
...
<li ID="hotel"></li>
...
</ul>
If I were to click on any of these elements, would it be possible to find out which child number they are in the list, and pass that value to a variable?
Yes, the jQuery index method will give you that info:
$(this).index(); // will return the index relative to its other siblings.
http://api.jquery.com/index/
As of 1.4,
$('li').click(function(){
alert( $(this).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