jQuery hasClass()Method

jQuery HTML/CSS 方法jQuery HTML/CSS Methods

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.


jQuery HTML/CSS 方法jQuery HTML/CSS Methods

Other Extensions