Remove empty list item using jquery

I have a list that is dynamically built, but there are empty list items that need to be removed.

<ul>
<li>www</li>
<li>www</li>
<li>www</li>
<li></li>
<li></li>
<li></li>
</ul>

How to do it using jQuery?

+3
source share
3 answers
$('ul li').filter(function() {return $(this).text()​​​​​​​ == '';}).remove();​
+5
source
$('ul li:empty').remove();
+17
source
$('ul').find('li').each(function(){
    if($(this).is(':empty'))
        $(this).remove();
});

Please use the Andy implementation (above mine :))

0
source

Source: https://habr.com/ru/post/1741242/


All Articles