Why does not work code?

Welcome

There is a modal window that opens and closes here this code:
var modal = document.getElementById('myModal');
var span = document.getElementsByClassName("close")[0];

span.onclick = function() {
 modal.style.display = "none";
}
window.onclick = function(event) {
 if (event.target == modal) {
 modal.style.display = "none";
}
}
function show(){modal.style.display = "block";}
function hide(){modal.style.display = "none";} 
setTimeout(hide, 2000);


Questions:
1. the first discovery - the window closes after 2 seconds, the second opening and the window itself doesn't close. Why?

2. the same when on this page: spoonerdance.com/gallery/tancevalnaya-moskviya-201...
The window opens but does not close automatically. Why?

Thanks in advance!
March 19th 20 at 08:31
1 answer
March 19th 20 at 08:33
Solution
Here have thrown the example, everything works as it should (in my opinion). If you think it works incorrectly, write what is it not meet Your expectations.
super, what you need
thank you! - lillian commented on March 19th 20 at 08:36

Find more questions by tags JavaScript