Skip to content

Instantly share code, notes, and snippets.

@desoga10
Created October 6, 2020 01:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save desoga10/6c7880bf7025c488ae0e32fca224c9c5 to your computer and use it in GitHub Desktop.
let modal = document.querySelector(".modal");
let show = document.querySelector(".show");
let closeButton = document.querySelector(".close-button");
function toggleModal() {
modal.classList.toggle("show-modal");
}
function windowOnClick(event) {
if (event.target === modal) {
toggleModal();
}
}
show.addEventListener("click", toggleModal);
closeButton.addEventListener("click", toggleModal);
window.addEventListener("click", windowOnClick);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment