Answer the question
In order to leave comments, you need to log in
How to add/remove classes from a block when a button is clicked?
Hello.
There is a code .
At the moment, when you click on the button, the class of the button we clicked on is added to the block, as a result, these classes simply accumulate in the block, how to make the classes be deleted, that is, when you click on the button, its class is added to the block, on the next click, the class that was added should the class be deleted and added from the new button (which was clicked) ?
Answer the question
In order to leave comments, you need to log in
Before each addition, clear all classes for this block, and then add a new class:
$('#block-id').removeClass().addClass('new-class-from-btn');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question