Method 1: Using hasClass() method: The hasClass() is an inbuilt method in jQuery which check whether the elements with the specified class name exists or not. It returns a boolean value specifying whether the class exists in the element or not. This can be used to check for multiple classes.
Method 2: Using is() method: This is similar to the above method and can be used to check more attributes if needed. The required element is selected and the class name is passed on like a CSS class selector. It returns a boolean value specifying whether the class exists in the element or not. This can be used to check for multiple classes.
- How to add class to an element without addClass() method in jQuery ?
- How to check an element has certain CSS style using jQuery ?
- How to check if an element is hidden in jQuery?
- How to check an element is visible or not using jQuery?
- How to check an HTML element is empty using jQuery ?
- How to find the parent class name with known class in jQuery ?
- How to remove parent element except its child element using jQuery ?
- How to select a div with a certain class using jQuery ?
- jQuery | .class Selector
- Not class selector in jQuery
- How to select all elements without a given class using jQuery ?
- jQuery | Move an element into another element
- How to create a CSS rule or class at runtime using jQuery ?
- How to fire event if CSS class is changed using jQuery ?
- jQuery | element + next Selector
- How to get a DOM Element from a jQuery Selector ?
- How to get focused element using jQuery?
- How to select an element by name with jQuery?
- How to change the element id using jQuery ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.