title: Executing JavaScript in the <head>, getElementById returns null
body: <p>I have following code</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script language="JavaScript"&gt;
  
  function foo(q) {
      this.run=function(color){
          var x=document.getElementById("ff");
          alert(x); // &lt;----x=null
      };
  
  }
  
  var q=new foo();
  q.run("yellow");
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div id="ff"&gt;&lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>does anyone has idea why <code>x=null</code></p>