D
D
Denis Kuzmin2021-06-09 16:49:57
JavaScript
Denis Kuzmin, 2021-06-09 16:49:57

How to remove/add a class from one element and add/remove a class to another?

How to make that when you click on "Set 2" closes "Set 1" and vice versa? That is, so that when you click on "Set 1" from "Set 2" the .opened class is removed and the .closed class appears

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-06-09
@DenKuzmin

$('.section').on('click', '.control-label', function() {
  $(this)
    .closest('.box')
    .toggleClass('opened')
    .siblings()
    .removeClass('opened');
});

The additional closed class is not needed, let the content be hidden by default. Accordingly, the styles need to be tweaked a bit:
.box .list {
  display: none;
}
.box.opened .list {
  display: block;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question