Answer the question
In order to leave comments, you need to log in
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
$(".checkbox").click(function(){
$(this).addClass("selected")
.siblings(".checkbox").removeClass("selected");
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question