var modal = document.getElementById('myModal'); var btn = document.getElementById("settings"); btn.onclick = function() { modal.style.display = "block"; } window.onclick = function(event) { if (event.target == modal) { console.log(event.target); modal.style.display = "none"; } }