Skip to content

Instantly share code, notes, and snippets.

@AlexKardone
Created April 28, 2019 07:47
Show Gist options
  • Save AlexKardone/4b2d228101279412f3a6796fed3aa32f to your computer and use it in GitHub Desktop.
Save AlexKardone/4b2d228101279412f3a6796fed3aa32f to your computer and use it in GitHub Desktop.
Close popup when click outside it
// get the container of the popup window
var wind = setup.querySelector('.popup-window');
var closePopup = function() {
setup.classList.add('hidden');
};
document.body.addEventListener('click', function(evt) {
if (!wind.contains(evt.target)) {
closePopup();
}
}, true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment