Why document.write doesn't wait the loading?
<p>Basically I have a <code>script.js</code> in my website that does this:</p>

<pre><code>if (someVar){
   document.write('&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"&gt;&lt;\/script&gt;');
}
</code></pre>

<p>Now I would like to attack some behaviour:</p>

<pre><code>if (someVar){
   document.write('&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"&gt;&lt;\/script&gt;');

  $(document).ready(function(){
     //&gt; Do stuff
  });
}
</code></pre>

<p>But I got undeclared function <code>$</code> in console </p>
