jquery选择器使得子节点不包含多个类?

时间:2018-02-26 21:44:51

标签: jquery jquery-selectors

我正在尝试编写一个选择器,只有当他们的孩子不包含以下3个班级时才选择<div>class="my-rating"

示例html:

<div class="my-rating" id="parentA">
    <div class="foo"></div>
</div>
<div class="my-rating" id="parentB">
</div>
<div class="my-rating" id="parentC">
    <div class="rating-full-star"></div>
    <div class="rating-full-star"></div>
    <div class="rating-full-star"></div>
    <div class="rating-half-star"></div>
    <div class="rating-empty-star"></div>
    <div class="bar"></div>
</div>
<div class="my-rating" id="parentD">
    <div class="rating-full-star"></div>
    <div class="rating-full-star"></div>
    <div class="rating-full-star"></div>
    <div class="rating-half-star"></div>
    <div class="rating-empty-star"></div>
</div>

我想选择parentAparentB并排除C和D.

这样的事情:

$('.my-rating').children().filter(':not(.rating-full-star):not(.rating-half-star):not(.rating-empty-star)')

除了这个家伙抓住所有孩子,而不是父母。我也尝试过:

$('.my-rating :not(.rating-full-star,.rating-half-star,.rating-empty-star)')

但这并没有抓住太多的东西。我能在这做什么?

1 个答案:

答案 0 :(得分:1)

你在这里:

$('.my-rating').not(':has(.rating-full-star, .rating-half-star, .rating-empty-star)');