如果ul为空,则隐藏div [英] Hide div if the ul is empty
本文介绍了如果ul为空,则隐藏div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的 html
,
<div id="personaldetails">
<ul>
<li class="clear"></li>
</ul>
<ul>
<li class="clear"></li>
</ul>
</div>
我想隐藏 div
personaldetails
当div中的所有ul都为空时。
I want to hide div
personaldetails
when all the ul inside in div is empty.
如果 ul
有元素< li class =clear>< / li>
,那么 ul
是被认为是空的。
If the ul
is having element <li class="clear"></li>
then the ul
is considered as to be empty.
如何使用Jquery执行此操作?
How to do this using Jquery ?
推荐答案
You can try this:
$('#personaldetails').find('ul').each(function(){
var txt = $("li", this).text();
if(txt.length <= 0){
$(this).hide();
}
});
if(!$('#personaldetails').find('ul:visible').length){
$('#personaldetails').hide();
}
更新小提琴
对我而言,您应该隐藏所有 ul
,如果没有ul可见,那么你可以隐藏 #personaldetails
div。
Updated Fiddle
And to me you should hide all ul
, if no ul are visible then you can hide the #personaldetails
div.
这篇关于如果ul为空,则隐藏div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文