list modal js

PHOTO EMBED

Tue Feb 22 2022 20:45:25 GMT+0000 (UTC)

Saved by @viresh #html

// take refernece of html elements
const listModalWrapper = document.querySelector("#list-modal-wrapper");
const listModalDemoBtn = document.querySelector("#list-modal-demo-btn");
const actionBtns = document.querySelectorAll(".btn-action");
const body = document.querySelector("body");

// event listener for live demo button for list modal
listModalDemoBtn.addEventListener("click", () => {
  listModalWrapper.style.display = "flex";
});

// event listeners for buttons in modal
// here for example i just closed modal on click on action ,
// you can perform any action you want to do on click of action buttons
actionBtns.forEach(btn => {
  btn.addEventListener("click", () => {
    if (btn.parentNode.id === "list-modal-buttons") {
      listModalWrapper.style.display = "none";
    }
  });
});

//event listener for closing modal when it is open and we click anywhere on screen/window
window.addEventListener("click", event => {
   if (event.target === listModalWrapper) {
    listModalWrapper.style.display = "none";
  }
});
content_copyCOPY