内容简介:翻译自: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
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Algorithms in C (Computer Science Series)
Robert Sedgewick / Addison-Wesley Professional / 1990-01-11 / USD 59.99
This new version of the best-selling book, Algorithms, SecondEdition, provides a comprehensive collection of algorithmsimplemented in C. A variety of algorithms are described in eachofthe following ar......一起来看看 《Algorithms in C (Computer Science Series)》 这本书的介绍吧!
HTML 编码/解码
HTML 编码/解码
UNIX 时间戳转换
UNIX 时间戳转换