title: How to simulate a click to make the current input lose its focus with JavaScript
body: <p>I have an input which at some points happens to have the focus. If the user click in the "background" of the page, the input loses its focus. I was trying to simulate the click on the background with the following code, but this doesn't work (you will notice that the input still has the focus). Any suggestion on how to write code that simulates a click on the "background" of the page?</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt;
          &lt;script type="text/javascript" src="http://yui.yahooapis.com/2.6.0/build/yahoo/yahoo-min.js" &gt;&lt;/script&gt;
          &lt;script type="text/javascript" src="http://yui.yahooapis.com/2.6.0/build/event/event-min.js" &gt;&lt;/script&gt;
          &lt;script type="text/javascript"&gt;
              YAHOO.util.Event.onDOMReady(function() {
                  document.getElementById("input").focus();    
                  document.getElementById("main").focus();    
              });
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div id="main"&gt;
              &lt;form action="/"&gt;
                  &lt;p&gt;
                      &lt;input type="text" id="input"/&gt;
                  &lt;/p&gt;
              &lt;/form&gt;
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>