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