Answer the question
In order to leave comments, you need to log in
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");
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question