

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use hasClass() method in jQuery?
The hasClass() method is used to check if an element has a class. You can try to run the following code to learn how to use hasClass() method in jQuery −
Example
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ alert($("h1").hasClass("myclass")); }); }); </script> <style> .myclass { color: blue; } </style> </head> <body> <h1 class="myclass">Heading</h1> <p>This is demo text.</p> <button>Check: The h1 element has 'myclass' class?</button> </body> </html>
- Related Questions & Answers
- jQuery hasClass() with Examples
- How to use removeClass() method in jQuery?
- How to use jQuery.wrapInner() method in jQuery?
- How to use jQuery.wrapAll() method in jQuery?
- How to use jQuery.text() method in jQuery?
- How to use jQuery.insertBefore() method in jQuery?
- How to use jQuery.insertAfter() method in jQuery?
- How to use jQuery.toggle() method in jQuery?
- How to use $.fadeTo() method to create animation in jQuery?
- How to use POST method to send data in jQuery Ajax?
- How to use GET method to send data in jQuery Ajax?
- Where do we use $.extend() method in jQuery?
- Why do we use JSON.stringify() method in jQuery?
- How to use universal (*) selector in jQuery?
- How to use attr() method in jQuery to get the value of an attribute?
Advertisements