<ul id="someList">
<li id="listItem1">List 1</li>
<li id="listItem2">List 2</li>
</ul>
Maybe I need to brush up on my selectors, but how would you grab the first ID of ul#someList?
Also if I'm prepending LI's to ul#someList, will I need to grab the first LI's ID in a different way?
$('ul#someList li:first')
is what you're looking for.
Your best bet is to use the first selector.
var id = $("ul#someList li:first").attr("id");
or
var id = $("ul#someList li:first").get(0).id;
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