Posted inJavaScript / jQuery

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

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype