Home/Jquery/.hasClass() method in Jquery

.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: 

dotnet-helpers-com-jquery-hasclass-method-thiyagu-jquery

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. 

dotnet-helpers-com-jquery-hasclass-method-thiyagu

 

READ  .insertAfter() method in Jquery

Leave A Comment