Search code snippets, questions, articles...

Check if element has a class jQuery


If you want to check whether a class is assigned to an element or not you can use .hasClass() method of jQuery. In the code snippet, we are checking if the div element has a class 'trophy' or not. It will return boolean true if it has a class 'trophy' and false if it has not class 'trophy'.

Search Index Data (The code snippet can also be found with below search text)

.hasClass() jQuery
Check if div contains a class jQuery
Was this helpful?