您好,我有以下HTML结构作为示例:
<body>
Testing hiding DIVs
<div class="content-1">
<h2>Hello - this is div 1</h2>
<div class="content-2">
<h2>Hello - this os div 2</h2>
</body>只有当div" content -1“包含或有内容时,我才会隐藏div "content-2”。
使用jquery实现这一点的最简单方法是什么?
非常感谢您的建议……
发布于 2013-06-24 23:18:26
你可以试试这个--(不过你应该关闭你的div )
if($('.content-1').contents().length > 0){
$('.content-2').hide();
}发布于 2013-06-24 23:19:54
if ($('div.content-1:not(:empty)').length) $('div.content-2').hide();发布于 2013-06-24 23:19:00
if($(".content-2").html().length > 0)
$(".content-1").hide();编辑-最初误读了这个--更改了布尔表达式。
https://stackoverflow.com/questions/17279007
复制相似问题