112
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.
jQuery hasClass() method example 2
Let’s take another example to demonstrate jQuery hasClass() method.
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
Here both the conditions will be true.
jQuery hasClass() Example 4
Next TopicjQuery toggleClass()