English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery hasClass() Method

jQuery HTML/CSS Methods

The hasClass() method checks if the selected element contains the specified class name.

The hasClass() method will return true if the specified class name is included.

Syntax:

$(selector).hasClass(className)

Example

Check if any <p> element has a class named "highlight":

$("button").click(function(){
  alert($("p").hasClass("highlight"));
});
Test and see‹/›

An element may be assigned more than one class:

$("p").click(function(){
  alert($(this).hasClass("blue"));
});
Test and see‹/›

Parameter Value

ParametersDescription
classNameThe class name to search for

jQuery HTML/CSS Methods