T
T
timtimIT2015-11-09 01:23:45
JavaScript
timtimIT, 2015-11-09 01:23:45

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

1 answer(s)
Y
yakalashnikov, 2015-11-09
@timtimIT

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 question

Ask a Question

731 491 924 answers to any question