English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
$(selector).hasClass(className)
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‹/›
Parameters | Description |
---|---|
className | The class name to search for |