I’m trying to simply remove all nested li elements within ul, but it is not working. Why won’t this snippet work? What am I missing?
html
<ul id="myul">
</ul>
<br/>
<button onclick="add();">add</button><br/>
<button onclick="remAll();">remove all</button>
js
function add()
{
$('#myul').append('<li>hello world</li>');
}
function remAll()
{
$('#myul').remove('li');
}
Do this instead, the selector argument for
remove()is a filter for the object in question.In this case the object in question is just the single element with the id
myUl, therefore not containing any<li>elements.jsFiddle
or