隐藏空的< li> [英] Hide empty <li>

查看:91
本文介绍了隐藏空的< li>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果所有<li>为空或<li>中有空格,我想隐藏所有<li>.

I want to hide all the <li> if they are empty or if there any blank space in <li>.

我正在这样做:

$("li:empty").filter(function(i,v){return $.trim($(v).text()).length == 0;}).css('display', 'none');

这是错误的语法吗?

如果我创建了一个使空的<li>不可见的类,则它可以正常工作.像这样:

If I create a class to make empty <li> invisible, it works fine. Like this:

$("li[class='hideLi']").filter(function(i,v){return $.trim($(v).text()).length == 0;}).css('display', 'none');

但是我不知道哪个<li>将为空.

But I don't know which <li> will be empty .

有人可以帮助我吗? 如果<li>为空,我想做display=none.

Can anybody help me plz. I want to do display=none if the <li> is empty.

这是我的代码:-

<script src="http://code.jquery.com/jquery-latest.js"></script>




<script>
  $(document).ready(function(){
    $("td:empty").css('display', 'none');
     $("div:empty").css('display', 'none');
     $(!$.trim('li:empty')).hide();
     $("li[class='hideLi']").filter(function(i,v){return $.trim($(v).text()).length == 0;}).css('display', 'none');
  });
  </script>

<ul>
  <li style="border:red solid 1px ">HI</li>
  <li style="border:green solid 1px ">  </li>
    <li style="border:blue solid 1px " class="hideLi">  </li>
  </ul>

谢谢

推荐答案

$('li').filter(function(){
    return $.trim($(this).html()) == '';
}).hide()

这篇关于隐藏空的&lt; li&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆