Good day.

How in javascript to "close" a div when clicked outside of this diva?

The same question, just need to write without jQuery .

  • The last answer on the link does not fit? - Ponio
  • jquery was used there - Tigran
  • You have already been given an answer, but in fairness - the last answer is by reference - without jquery. - Ponio
  • @Ponio There is close, but not quite. - user194374

1 answer 1

This is done, for example, as follows:

document.onclick = function() { document.getElementById("block").style.display = "none"; } function onDivClick(e) { e = e || window.event; e.stopPropagation(); } 
 #block { background-color: #ddf; border: 2px solid #ffd; width: 100px; height: 100px; } 
 <div id="block" onclick="onDivClick(event);"></div>