jquery 判断标签内元素内容为空时,隐藏该模块

<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<title>判断元素为空时隐藏</title>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>


<script>
    ....
</script>


<style>
    .box{
        width: 50px;
        height: 50px;
        background: red;
    }
</style>
<body>


<div class="box">
    <h1>111</h1>
</div>




<div class="box">
    <h1>222</h1>
</div>




<div class="box">
    <h1>333</h1>
</div>




<div class="box">
    <h1></h1>
</div>



</body>
</html>

判断如果h1内容为空时,隐藏该box~~试了一下,都没实现

阅读 10.2k
2 个回答
$("h1:empty").parent().hide()
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进