Site icon Dotnet Helpers

.hasClass() method in Jquery

Description:

The Jquery hasClass() method validate whethere selected elements having a specified class name or not. If selected elements has matched class name then it will return “true” else it will return “false”.

Syntax

.hasClass( className )

className  It specify the class name to search whether its present or not

Example: 

Output: 

On clicking “Add CSS Class” button then the “if” condition will execute and append the “selected” class to the matched div. The CSS class will append only if it receive true from the .hasClass() method. 

 

Exit mobile version