L
L
lavezzi12015-10-31 13:13:31
css
lavezzi1, 2015-10-31 13:13:31

jQuery question about adding/removing classes?

Hello. It is necessary to implement color selection, let's say there are 5 blocks\checkboxes, only one can be selected. How to implement such a mechanism in jquery? That is, you click on one checkbox, it is selected, you click on another, it is selected, and the previous one is removed. It is necessary to add a class, since the checkboxes are custom. addClass, removeClass, toggleClass - I know, but I find it difficult to implement such a mechanism.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Inchin ☢, 2015-10-31
@lavezzi1

$(".checkbox").click(function(){
  $(this).addClass("selected")
      .siblings(".checkbox").removeClass("selected");
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question