Vanila javascript to jquery modal popup

blossom0417
1 min readJun 19, 2019

--

you want to close a modal popup , when the user clicks anywhere outside of the modal,

//vanila
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
  • Jquery
$(window).click(function(e) {   if (e.target.id == 'modal') {
console.log('event.target',$(e.target))
modal.css('display','none')
}

});
e.target.id == 'modal' $(event.target).attr('class') = 'modal'

why wouldn’t think this?

I’ve spent 30 mins figuring this out! wow.

--

--

No responses yet