最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Remove empty list item with jquery - Stack Overflow

programmeradmin3浏览0评论

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 badges
Add a comment  | 

3 Answers 3

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 :))

发布评论

评论列表(0)

  1. 暂无评论