2022-05-03 19:07:12 -06:00

27 lines
741 B
JavaScript

// Get the modal
const modal = document.querySelector(".modal-menu");
// Get the button that opens the modal
const btn = document.querySelector(".open-modal");
console.log(modal)
// Get the <span> element that closes the modal
const span = document.querySelector(".close-modal");
// When the user clicks on the button, open the modal
btn.addEventListener("click", event => {
modal.style.display = "block";
})
// When the user clicks on <span> (x), close the modal
span.addEventListener("click", event => {
modal.style.display = "none";
})
// When the user clicks anywhere outside of the modal, close it
window.addEventListener("click", event => {
if (event.target == modal) {
modal.style.display = "none";
}
});