How to check a class exists on page or on html element.

0
Our Reader Score
[Total: 0 Average: 0]
 jQuery .hasClass() : This article explains how to Check whether an element has particular class. i.e how to find div contains certain class name exists.

In below sample code will show you how to get all div tags having class name public and then will change text of it.

In jquery this can be done with .hasClass( className ) method.

Syntax:

.hasClass( className ) // return boolean (true/false).

Description: Determine whether any of the matched elements is assigned the given class.

Here on button click will check whether a div tag contains specific class i.e here in our case we are checking for class name public as shown in below code.

Conclusion:

Using .hasClass() jquery method will find out whether specfic element contains specific class.

Hope you enjoy this tutorial.


Get your Printable Copy

NO COMMENTS

LEAVE A REPLY