Using .index() we can get the position or index of an element. Now i want to know that
can we get the element’s id using its index ?
An Example,
<ul id="unOrderedList">
<li id="gears"><a class="links" href="#">Click here!</a></li>
<li id="tyres"><a class="links" href="#">Click here!</a></li>
<li id="rear"><a class="links" href="#">Click here!</a></li>
<li id="mirror"><a class="links" href="#">Click here!</a></li>
<li id="charger"><a class="links" href="#">Click here!</a></li>
<li id="port"><a class="links" href="#">Click here!</a></li>
<li id="list"><a class="links" href="#">Click here!</a></li>
</ul>
For the above mark up, if i want to know 4th <li> id means, how shall it do it with jquery?
Thanks in Advance!
If you have the index ahead of time, just use the
:eqselector, like so:or use the
.eqfilter method:EDIT: I’m guessing that this is what you’re after:
Try it here.