Example

Check if any p element has an "intro" class:

$("button").click(function(){
  alert($("p").hasClass("intro"));
});

Try it yourself »

Definition and Usage

The hasClass() method checks if any of the selected elements have a specified class.

If ANY of the selected elements has the specified class, this method will return "true".

Syntax

$(selector).hasClass(class)

Parameter Description
class Required. Specifies the class to search for in the selected elements