Open In App

How to add class to an element without addClass() method in jQuery ?

The task is to add a new class to the element without using addClass() method with the help of jQuery. There are two approaches that are discussed below:

Approach 1: To perform the operation, we can use toggleClass() method to toggle the class which we want to add to the element.

Approach 2: We can also use attr() method and prop() method to add a new attribute ‘class’ to the element.


Article Tags :