根据条件隐藏Div

Dev*_*v P 0 html jquery

嗨,我有以下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>
Run Code Online (Sandbox Code Playgroud)

我想隐藏div"content-2"只有div"content-1"包含或包含内容.

使用jquery实现这一目标的最简单方法是什么?

非常感谢任何建议......

Moh*_*dil 5

你可以试试这个- (应关闭div,虽然)

if($('.content-1').contents().length > 0){
  $('.content-2').hide();
}
Run Code Online (Sandbox Code Playgroud)