jQuery Tutorial
jQuery hasClass() Method With Syntax and Example
What is hasClass method in jQuery?
The hasClass()
method determines whether any selected elements belong to a specific class.
This method will return "true" if any selected elements have the specified class name.
Syntax of hasClass method in jQuery
$(selector).hasClass(classname)
Example of jQuery hasClass method
Check if any element has a class named "intro"
:
$("button").click(function(){
alert($("p").hasClass("intro"));
});