开发者

Testing if an element has a certain class with jQuery

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜