[英]Jquery inArray() method to find a class in a Jquery Object
Suppose I have a Jquery Object $('.class0 .class1 .class2...')
. 假设我有一个Jquery对象$('.class0 .class1 .class2...')
。 I want to check if a class .classX
is in this object. 我想检查类.classX
是否在此对象中。 How can I do this? 我怎样才能做到这一点? I don't think inArray()
is not adapted 我不认为inArray()
不适合
In the same time, just to make things clearer for me, if I have a Jquery Object $('.class0, .class1, .class2, ...')
if I want to check if a class .classX
is in this object, I should use inArray()
method, right? 同时,为了让我更清楚,如果我有一个jQuery对象$('.class0, .class1, .class2, ...')
如果我想检查该对象中是否有类.classX
, ,我应该使用inArray()
方法,对吗?
如果jQuery对象中有一组元素,则可以使用filter()
:
var isInside = $(".class0, .class1, .class2, ...").filter(".classX").length > 0;
Use .hasClass()
. 使用.hasClass()
。
var hasClass = $obj.hasClass("classX");
Notice there no dot ( .
) character prefixing classX
. 请注意,没有前缀classX
点( .
)字符。
$('.class0, .class1, .class2').is('.class2');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.