title: click anywhere to close div inside and outside
body: <p>This is a jscript to close the window when someone clicks anywhere outsite the Div to close.
  my question is to make this window close when someone clicks on this by performing the action.</p>
  
  <pre><code>&lt;div id="box"
  style="height: 3em; position:absolute; top: 20%; left: 15%; border: 3px double"&gt;
  &lt;p&gt;Click anywhere outside this box to close it.
  &lt;/div&gt;
  &lt;script&gt;
  document.onclick = function (e) {
  e = e || event
  var target = e.target || e.srcElement
  var box = document.getElementById("box")
  do {
        if (box == target) {
             // Click occured inside the box, do nothing.
             return
        }
        target = target.parentNode
   } while (target)
   // Click was outside the box, hide it.
   box.style.display = "none"
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>How to make a Div close when the click was occurred inside the DIV</p>