javascript - 如何选择不包含某个子元素的元素?

标签 javascript jquery

<div class="test">
 <div class="example"></div>
</div>

<div class="test">
</div>

仅当类 test 不包含类 example 的子元素时,如何将 jQuery 应用于类 test 的元素?

最佳答案

$('.test:not(:has(.example))')

-或-

$('.test').not(':has(.example)')

关于javascript - 如何选择不包含某个子元素的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10168248/

相关文章:

javascript - 光滑的轮播 NPM

javascript - 测试 AngularUI Bootstrap 模式实例 Controller

javascript - jQuery 函数显示带有显示 : none 的 div

javascript - 使用动态值的 jquery 图表示例

javascript - 使用 Ajax 将多个对象发送到 ASP.NET MVC Controller

javascript - 使用 jQuery 使用 CSS 为文本着色

javascript - 以正确的方式删除对象的属性

javascript - 如何旋转 THREE.TubeGeometry 段?

javascript - jquery 从 html 方法中排除元素

php - 如何从动态数组类型字段中获取值