开发者

Testing if an element has a certain class with jQuery

开发者 https://www.devze.com 2023-02-20 15:34 出处:网络
I\'m trying to test for the presence of class intra-field-label on an element. This element wi开发者_如何学JAVAll have multiple classes. How may I do this?Use hasClass()

I'm trying to test for the presence of class intra-field-label on an element. This element wi开发者_如何学JAVAll have multiple classes. How may I do this?


Use hasClass()

http://api.jquery.com/hasClass/


if ($("#yourelementid").hasClass("intra-field-label")) {
    // your code goes here
}


For completeness, there's also .is() which takes any jQuery selector. This is more flexible, but for your particular case, Phil's answer is more appropriate.


The jquery selector for class is ".class", http://api.jquery.com/class-selector/

$('.intra-field-label')
0

精彩评论

暂无评论...
验证码 换一张
取 消