title: how to make javascript object disappear when click on rest of page
body: <p>How to change the following code so when clicking anywhere on the web page, the line "This is foo" will disappear, right now I have to click "Click here" to make it disappear.</p>
  
  <pre><code>&lt;html&gt;
  &lt;script type="text/javascript"&gt;
  &lt;!--
      function toggle_visibility(id) {
         var e = document.getElementById(id);
         if(e.style.display == 'block')
            e.style.display = 'none';
         else
            e.style.display = 'block';
      }
  //--&gt;
  &lt;/script&gt;
  &lt;body&gt;
  &lt;a href="#" onclick="toggle_visibility('foo');"&gt;Click here&lt;/a&gt;
  &lt;div id="foo"&gt;This is foo&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>