开发者

Remove empty list item with jquery

开发者 https://www.devze.com 2022-12-27 12:50 出处:网络
I have a list which is dynamically built, but there are empty list items which need removing. <ul>

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?


$('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 :))

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号