What is the jQuery hasClass() method?

The jQuery hasClass() is a built-in method used to check whether the selected elements, with a specified class name, exist or not. hasclass() returns a boolean value. If a specified class is present in any of the selected elements, a true value is returned; otherwise, ​the method returns a false value.

svg viewer

Code explanation

In the code above, the hasClass() method is used to check whether temp1 and temp2 have used red class or not. Since temp1 has used red class, it returns true, but temp2 used bold class, so it returns false.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved