本文介绍了如何选择不包含某个子元素的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<div class="test">
<div class="example"></div>
</div>
<div class="test">
</div>
如何将jQuery应用于类 test 只有当它不包含类
示例
的子元素时?
How can I apply jQuery to an element with the class
test
only if it doesn't contain a child element with the class example
?
推荐答案
$('.test:not(:has(.example))')
- 或 -
$('.test').not(':has(.example)')
这篇关于如何选择不包含某个子元素的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!