I have:
<ul id="ulId">
<li id="firstli">
</li>
<li id="secondli">
</li>
</ul>
and I am trying to remove secondli
.
This is what I have tried based on some reading.
$('#ulId secondli').remove();
and
$('#ulId > secondli').remove();
but these 2 methods did not work. Any suggestions?
To add new li to ul on click with JavaScript, we can call the appendChild method. const ul = document. getElementById("list"); const li = document. createElement("li"); li.
Try this:
$('#secondli').remove();
In jQuery, you refer to the ID of an element with a #
in front of it. See http://api.jquery.com/id-selector/
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