Let's say I have the following html
<ul>
<li id="a">a</li>
<li id="b">b</li>
<li id="c">c</li>
</ul>
<ul>
<li id="d">d</li>
<li id="e">e</li>
<li id="f">f</li>
</ul>
If I used jQuery to grab the item $('#e')
, how do I determine the position or position/index of e
relative to its siblings d
and f
? In other words, I'm expecting the value 1 (if zero based index) to be returned or 2 (if one based index) because it is the second element in the ul
list.
Simple: var idx = $('#e').index() // zero based
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