Javatpoint Logo
Javatpoint Logo

jQuery hasClass()

The jQuery hasClass() method is used to check whether selected elements have specified class name or not. It returns TRUE if the specified class is present in any of the selected elements otherwise it returns FALSE.

Syntax:

Parameters of jQuery hasClass() method

Parameter Description
className It is a mandatory parameter. It specifies the name of the CSS class to search for in the selected elements.

Example of jQuery hasClass() method

Let's take an example to demonstrate jQuery hasClass() method.

Test it Now

jQuery hasClass() method example 2

Let's take another example to demonstrate jQuery hasClass() method.

Test it Now

Here the first condition is true and the second is false. If we set the second paragraph class name ?blue? then both the conditions will be true.

jQuery hasClass() Example 3

Test it Now

Here both the conditions will be true.

jQuery hasClass() Example 4

Test it Now



Please Share

facebook twitter google plus pinterest tumbler

Latest 4 Tutorials