I have this code:
<ul id="hello">
<li>.....</li>
<li>.....</li>
<li>.....</li>
<li>.....</li>
<li>.....</li>
<li>.....</li>
</ul>
and this Script:
$("<label>The First item</label>").appendTo($('ul#hello li'));
How can I make it so that the .appendTo() function only applies to the first list item.
I've tried the :first-child selector but it doesn't seem to work.
Any help is appreciated.
$("<label>The First item</label>").appendTo($('#hello li:first'));
$("<label>The First item</label>").appendTo($('#hello li').first());
Note: .first() should be a tad faster than :first.
Also see: jQuery :first vs. .first()
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