jQuery hasClass()Method
Example
Check if the <p> element contains the "intro" class:
$("button").click(function(){
alert($("p").hasClass("intro"));
});
Try it Yourself »
Definition and Usage
The hasClass() method checks whether the selected element contains the specified class name.
If the selected element contains the specified class, the method returns "true".
Syntax
$(selector).hasClass(classname)
| Parameter | Description |
|---|---|
| classname | Required. Specifies the class to look for in the selected elements. |
Other Extensions
jQuery HTML/CSS Methods