What is jquery Hasclass? – jQuery Check if Element has Class

In this jquery hasclass demo with example, I will learn all about jquery .hasClass() function selector.hasClass( className ) – is used to check if an element has a each class or not. The has Class method will return true if the your used define each class name is assigned to an HTML element more data it returns true or false value.

All Question & Answers

jquery check if class exists on page using hasclass

  • The simple jQuery .hasClass() checks whether the selected HTML tag, class id or any element has the each class or not.
  • It returns a Boolean value Like as a (true or false).

The jQuery has Class() is a easy to use a built-in method used to check whether the selected all the HTML elements, with a check a specified class name, exist or not.

Using .hasClass()

jQuery .hasClass() determines whether HTML elements have a class you each. In the simple example below, the returns Boolean data value is returned like true or false after clicking a this button:

Jquery .hasClass() Syntax


In below example we have two classes (‘seokhazana’ , ‘katmoviehd’) associated with div tag.

It would return true value

$( "#mp4moviez" ).hasClass( "seokhazana" ); 

It would return true value

$( "#mp4moviez" ).hasClass( "katmoviehd" ); 

It would return false value. As no matching class name found.

$( "#mp4moviez" ).hasClass( "4cgandhi" ); 

Jquery .is() Function Source Code

In this Jquery .hasClass() Method Example We have multiple of li HTML elements which is associated with simple same class names (4cgandhi, seokhazana and katmoviehd) and on click of each button, We going to fade out some matching class name li HTML element.



Jquery has Class() function Example

  • 4cgandhi
  • seokhazana
  • seokhazana 4cgandhi
  • katmoviehd

Jquery .hasClass() Method Example


Note: here you Keep in mind it might have multiple classes. the .hasClass() jQuery will data return true if HTML an element has the each class.

jQuery full source code example to check whether a HTML web page element has a each css class attached.

I hope you get an idea about jquery has-class.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment