Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery hasClass() method

jQuery hasClass() method

jQuery HTML/CSS methods jQuery HTML/CSS methods

Example

Checks

Check whether the element contains the "intro" class:

$

(

"

button

"

)

.

click

(

function

(

)

{

alert

(

$

(

"

p

"

)

.

hasClass

(

"

intro

"

)

)

;

}

)

;

Try it »


Definition and Usage

The hasClass() method checks whether the selected elements contain the specified class name.

If the selected element contains the specified class, this method returns "true".


Syntax

$(

selector

).hasClass(

classname

)

Parameters Description
classname Required. Specifies the class to look for in the selected elements.

jQuery HTML/CSS methods jQuery HTML/CSS methods