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
- What is jquery Has class?
- How to add multiple class in jquery?
- How to select an element in jquery?
- How to get next element in jquery?
- How to get element by class in jquery?
- How to check if class exists in jquery?
- How to get all elements with same class in jquery?
- How to select first element in jquery?
- How to get class of element in jquery?
- How to add class after in jquery?
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
$(selector).hasClass(classname);
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.
index.html
Jquery has Class() function Example
- 4cgandhi
- seokhazana
- seokhazana 4cgandhi
- katmoviehd
Jquery .hasClass() Method Example
index.html
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.