$("ul").empty()
works fine. Is there some other error?
$('input').click(function() {
$('ul').empty()
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
<li>test</li>
<li>test</li>
</ul>
<input type="button" value="click me" />
http://jsfiddle.net/infernalbadger/D5ss8/
As noted by others, $('ul').empty()
works fine, as does:
$('ul li').remove();
JS Fiddle demo.
This should work:
$("ul").html('')
$("ul").empty() should work and clear the childrens. you can see it here:
http://jsfiddle.net/ZKFA5/
var ul = document.getElementById("yourElementId");
while (ul.firstChild)
ul.removeChild(ul.firstChild);
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