jQuery选择器:当存在多个类时选择某个类的组合 [英] jQuery selector: Selecting a certain combination of classes when multiple exist
问题描述
我已经尝试过做一些研究但没找到任何东西,但如果我错过了答案,请告诉我。基本上我有多个元素,每个元素有多个类,但组合是唯一的。我想选择某种类的组合,但不要选择其他元素与其他元素结合使用。
I have tried to do some research already and haven't found anything, but If I've missed the answer, please tell me. Basically I have multiple elements with multiple classes each, but the combinations are unique. I want to select a certain combination of classes, but not other elements that have this elements in combination with others.
我想知道这个选择器是否存在于jQuery中,或者是否还有其他方法可以实现我所解释的内容。请参阅以下示例:
I would like to know if this selector exists in jQuery or if there is some other way to accomplish what I am explaining. See the example below:
<div class="a b c"></div>
<div class="a b c d"></div>
<div class="a b c d">/div>
当尝试仅记录类 abc $ c的元素时$ c>,我尝试使用:
When trying to log only the element with the classes a b c
, I tried using:
$('.a.b.c').each( function() {
console.log($(this));
}
输出为:
[ <div class="a b c">...</div> ,
<div class="a b c d">...</div ,
<div class="a b c d">...</div> ]
我正在寻找输出:
[ <div class="a b c">...</div> ]
任何感谢指导。谢谢!
推荐答案
您可以使用CSS3 :not()
伪类否定 .d
class: (示例)
You could use the CSS3 :not()
pseudo class to negate the .d
class: (example)
$('.a.b.c:not(.d)').each( function() {
console.log($(this));
});
$('.a.b.c').not('.d').each( function() {
console.log($(this));
});
您还可以使用属性选择器: (示例)
[class="a b c"]
请注意,订单总是必须 ABC
。只是将其作为选项抛出。
Note that the order always has to be a b c
. Just throwing that out there as an option.
这篇关于jQuery选择器:当存在多个类时选择某个类的组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!