如果子div为空,则jQuery隐藏父div

栏目: jQuery · 发布时间: 6年前

内容简介:翻译自:https://stackoverflow.com/questions/11290432/jquery-hide-parent-div-if-child-div-is-empty

我环顾四周,发现了很多关于此的问题,但没有一个解决方案适合我.我有这样的结构:

<div class="pricetag">
    <div class="price">400</div>
</div>

<div class="pricetag">
    <div class="price"></div>
</div>

<div class="pricetag">
    <div class="price">250</div>
</div>

我想要做的是隐藏.pricetag,其中.price不包含任何内容.

它可以在同一页面上有很多不同的.pricetag,但我只想隐藏那些空的.price.

这有可能与jQuery?我尝试了很多不同的脚本但没有一个正常工作.

假设空的.price元素永远不会包含任何文本节点(例如换行符号),则可以使用 :empty 选择器和 parent 方法:
$(".price:empty").parent().hide();

这是 working example .

翻译自:https://stackoverflow.com/questions/11290432/jquery-hide-parent-div-if-child-div-is-empty


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Developer's Guide to Social Programming

Developer's Guide to Social Programming

Mark D. Hawker / Addison-Wesley Professional / 2010-8-25 / USD 39.99

In The Developer's Guide to Social Programming, Mark Hawker shows developers how to build applications that integrate with the major social networking sites. Unlike competitive books that focus on a s......一起来看看 《Developer's Guide to Social Programming》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

MD5 加密
MD5 加密

MD5 加密工具