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')
精彩评论