Reputation: 26281
Starting from $('#selected')
, what would be the best way to select the first list item?
<ul>
<li>first</li>
<li>second</li>
<li id="selected">third</li>
</ul>
Upvotes: 0
Views: 43
Reputation: 120
$('#selected').parentNode.children[0]
or
$('#selected').parentNode.firstChild
are both options, despite not being all jQuery.
Upvotes: 0
Reputation: 38112
You can use .siblings() along with .first() or :first selector:
$('#selected').siblings('li:first') // or $('#selected').siblings('li').first()
Upvotes: 4