TransWikia.com

Как исправить код закрытия окон?

Stack Overflow на русском Asked by user389240 on January 10, 2021

Как можно сделать функцию с названием closeAllPopups что бы задействовала данный код ?

window.addEventListener("keydown", function(e) {
    if (e.keyCode == 27 && editPopup.classList.contains('popup_active')) {
        editPopup.classList.remove('popup_active');
    }
    if (e.keyCode == 27 && addPopup.classList.contains('popup_active')) {
        addPopup.classList.remove('popup_active');
    }
    if (e.keyCode == 27 && imagePopup.classList.contains('popup_active')) {
        imagePopup.classList.remove('popup_active');
    }
}, true);

One Answer

function closeAllPopups() {
  document.querySelectorAll('.popup_active').forEach(i => i.classList.remove('popup_active'));
}

window.addEventListener("keydown", function(e) {
  if (e.keyCode == 27)
    closeAllPopups();
}, true);

Correct answer by Igor on January 10, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP