M
M
microf2020-04-18 17:52:49
JavaScript
microf, 2020-04-18 17:52:49

How to close a modal window when opening another one?

Good afternoon.
There are three buttons with different IDs. Clicking on them opens the corresponding windows. But when you click on the next one, the previous one doesn't close. I understand how to do it with tabs, but I can't quickly figure out how to do it now.

jsfiddle

let toolbar = document.querySelector('.toolbar');

toolbar.onclick = function(event) {
  let target = event.target.closest('a');

  if (target.tagName != 'A') return;
  let modalActive = document.querySelector('#' + target.dataset.target);
  modalActive.classList.toggle("modal-window--active");
};

jsfiddle

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
be_a_man, 2020-04-18
@microf

For example, like this
Or like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question