I have 2 pop-up modals in a webpage which i want to close if the user clicks anywhere outside the modal. The problem is only the 2nd one works 1st doesn't.
// When the user clicks anywhere outside of the modal1, close it
window.onclick = function(event){
if (event.target == modal1) {
modal1.style.display = "none";
}}
//When the user clicks anywhere outside of the modal2, close it
window.onclick = function(event) {
if (event.target == modal2) {
modal2.style.display = "none";
}}