How to add and remove a class to an anchor tag with jQuery?

To add and remove a class to an anchor tag, use the toggleClass. Using it you can add and remove a class on a click.

You can try to run the following code to learn how to add and remove a class to an anchor tag with jQuery ?

Example

   
      
      

      

   
   
      Click me
      

The above will add and remove class (change color) on click.

   
Updated on: 2026-03-11T20:54:41+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements