Dynamically load jquery
<p>I'm working in a really twisted environment in which I cannot handle this problem through the view logic of the MVC framework I'm using (Cakephp). It could happen because I have to load this piece of code inside a page which already has a jQuery script loaded in. </p>

<p>If I simply load jQuery in my piece of code, it works as long as there's no other jQuery scripts present. When there are 2 scripts, it doesn't work and says <code>$ is not a function</code>. Not really sure how this works but explanations could help.</p>

<p>Anyway I've got to the point of dynamically loading the script into the page. </p>

<p>So this is my code:</p>

<pre><code>&lt;script id="loadjq" type="text/javascript"&gt;&lt;/script&gt;
&lt;script id="loadcloud" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
if(typeof jQuery=="undefined"){
    document.getElementById('loadjq').src= 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js';
}
document.getElementById('loadcloud').src= '/js/jqcloud.js';
$(document).ready(function(){
    $("#tagcloud").jQCloud(word_list,{});
});
&lt;/script&gt;
</code></pre>

<p>This loads the script but when I try to load jqcloud.js, it can't find the other script, probably because it runs before the other script is loaded. With a few dirty tricks I could go through that, but the same problem happens when i reach     <code>$(document).ready(function()</code> </p>

<p>Is there a clean way to do this? I need it to wait for the previous scripts to be loaded before executing, or at least, that's what the problem looks like. Not really sure if this is really my problem.</p>
