Click.toggle add / remove class

When I click #tool

, I want to add a class .spanner

to the div #drill

.

However, when #drill

has a class .spanner

and is #tool

clicked, I want the class to be removed?

+2


a source to share


1 answer


Use the function toggleClass

:



$("#tool").click(function() {
    $("#drill").toggleClass("spanner");
});

      

+7


a source







All Articles