如何隐藏/删除DIV时为空 [英] How to hide/remove a DIV when empty
本文介绍了如何隐藏/删除DIV时为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些服务器端HTML输出我不能使用纯CSS处理,基本上DIV有时拥有:
I have some server side HTML output I cannot deal with using pure CSS, essentially the DIV sometimes holds:
<div><span>Content</span></div>
或
<div><p>Content</p></div>
或
<div>Content</div>
或
<div> </div>
当DIV == < div&
When the DIV == <div> </div>
I want to remove it.
任何想法?
推荐答案
更好(假设jQuery):
Even better (assuming jQuery):
$(document).ready(function() { $('div:empty').remove(); });
编辑:其他答案是好的,但OP想要删除空项, 。
The other answers are good, but the OP wanted to remove the empty item, not hide it.
这篇关于如何隐藏/删除DIV时为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文