title: How can I check if jquery is loaded from external JS file?
body: <p>I have an external JS file to manage all script in my page.
  I want to write in this file some code to check if jquery plugin is loaded and (if not) load it!</p>
  
  <p>I tried to begin my myScripts.js file with this code:</p>
  
  <pre><code>if (typeof jQuery == 'undefined') {
      var script = document.createElement('script');
      script.type = "text/javascript";
      script.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js";
      document.getElementsByTagName('head')[0].appendChild(script);
  }
  </code></pre>
  
  <p>And in my index.html</p>
  
  <p>I did this:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="pt-br"&gt;
  
      &lt;head&gt;
          &lt;script src="myScripts.js"&gt;&lt;/script&gt;
  
      &lt;/head&gt;
  
      &lt;body&gt;
  
          &lt;button id="test"&gt;test&lt;/button&gt;
  
          &lt;script&gt;
  
          $('#test').click( function() {
  
              alert('clicked');
  
          });
  
          &lt;/script&gt;
      &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>But it's not performing the alert dialog.. What's wrong?</p>