Chrome Extension

Check if element has a class jQuery

$("div").hasClass("trophy");
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

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?
0 Comments
Join Devsheet Ask a Question