Reputation: 375
I have made a delay open modal, everything is working except one function - close when clicked outside the modal - when I click out of the modal it does not close, please can You help me why?
This is js code with the line which is not working:
window.addEventListener('click', outsideClick());
function outsideClick(event) {
if(event.target == modal) {
modal.style.display = ('none');
}
}
the whole modal is here: https://codepen.io/hubkubas/pen/wXpYwy
Upvotes: 0
Views: 150
Reputation: 2395
change event listener like this window.addEventListener('click', outsideClick);
Upvotes: 1
Reputation: 3458
Pass callback function like this (without brackets):
window.addEventListener('click', outsideClick);
Then outsideClick
will be called with default parameters and event
won't be undefined.
Upvotes: 1