How to remove <li> </li> from ul?
3 answers
It depends on what you have and what you add. Assuming you added items so they look like this:
<ul id="list">
<li><a href="#" class="clear">clear</a></li>
<li><a href="#" class="clear">clear</a></li>
<li><a href="#" class="clear">clear</a></li>
</ul>
then use remove()to remove one element:
$("#list a.clear").click(function() {
$(this).parent().remove();
return false;
});
but if you have:
<ul id="list">
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
<a href-"#" id="clear">Clear</a>
and you want to clear them all, use empty():
$("#clear").click(function() {
$("#list").empty();
return false;
});
+9