title: TypeError: $(selector) is null
body: <p>I have a web page that redirects to another page on click.
  On the second page I have this:</p>
  
  <pre><code>&lt;?php if(isset($_POST['tab1'])) { ?&gt;
    &lt;script&gt;$('#home').trigger('click'); &lt;/script&gt; 
  &lt;?php }?&gt;    
  </code></pre>
  
  <p>The <code>$_POST</code> comes back ok, only I get this error in the console for the jquery:</p>
  
  <p>In firebug:</p>
  
  <pre><code>TypeError: $("#home") is null
  </code></pre>
  
  <p>Or in Chrome:</p>
  
  <pre><code>$('#home').trigger('click');
  </code></pre>
  
  <p>If I run this: <code>alert(document.getElementsByTagName('#home'));</code></p>
  
  <p>I get a alert with: <code>[object HTMLCollection]</code> as <code>undefined</code></p>
  
  <p>If I view the source I can see my jquery there:</p>
  
  <pre><code>&lt;script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js"&gt;&lt;/script&gt;
  &lt;script&gt;
  !window.jQuery &amp;&amp; document.write('&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js"&gt;&lt;\/script&gt;');
  &lt;/script&gt;
  </code></pre>
  
  <p>Any ideas on why the jquery fails?</p>