I have a list which is dynamically built, but there are empty list items which need removing.
<ul>
<li>www</li>
<li>www</li>
<li>www</li>
<li></li>
<li></li>
<li></li>
</ul>
How do I do this with JQuery?
I have a list which is dynamically built, but there are empty list items which need removing.
<ul>
<li>www</li>
<li>www</li>
<li>www</li>
<li></li>
<li></li>
<li></li>
</ul>
How do I do this with JQuery?
Share Improve this question edited Sep 5, 2017 at 17:16 Erik Philips 54.6k11 gold badges131 silver badges156 bronze badges asked Apr 15, 2010 at 9:27 MarkMark 4883 gold badges13 silver badges30 bronze badges3 Answers
Reset to default 18$('ul li:empty').remove();
$('ul li').filter(function() {return $(this).text() == '';}).remove();
$('ul').find('li').each(function(){
if($(this).is(':empty'))
$(this).remove();
});
Please use Andy's implementation (above mine :))