Pittfall Pittfall - 2 months ago 14
jQuery Question

How do you remove and <li> from a <ul> by Id?

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?

Answer

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/