hasClass() method in jQuery

hasClass() in jQuery

Using hasClass() method, we can check if the specified class name is present in the specified element or not.

It returns true if the specified class name is present, else it returns false.

Syntax

$(selector).hasClass(className)

  • className - The class name to search for.

Example 1

Try Yourself

Example 2

Try Yourself

Example 3 - small usage

Try Yourself