I am trying to check if an attribute has a certain class on it:
$('span[last="lastWord"')
The above is what I have now. I want to check the span class with that attribute for its classes attribute... Basically what I'd like is a jQuery function to check that span class for a certain class. Hope that makes sense.
As @Pekka points out in the comments, jQuery already has a method hasClass
that allows you to do this:
$('span').hasClass('yourClass');
Otherwise, you can do it in plain JS like:
// assuming you already have a reference to your element
function hasClass(elem, myClass) {
return elem.classList.indexOf(myClass) !== -1;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.