title: document.head.appendChild not working
body: <p>I am trying to append jQuery library via JavaScript code like this:</p>
  
  <pre><code>    var script = document.createElement('script')
      script.type = 'text/javascript'
      script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js'
      document.head.appendChild(script);
  
  if (window.jQuery) {  
      document.write('jQuery is loaded') 
  } else {
      document.write('jQuery is not loaded');
  }
  </code></pre>
  
  <p>The above code is not executing the src file and I am not able to find jQuery element. To confirm I have added this piece of code:</p>
  
  <pre><code>if (window.jQuery) {  
      document.write('jQuery is loaded') 
  } else {
      document.write('jQuery is not loaded');
  }
  </code></pre>
  
  <p>JsFiddle: <a href="https://jsfiddle.net/vyeyhrrL/" rel="nofollow">https://jsfiddle.net/vyeyhrrL/</a></p>
  
  <p>The output I am seeing is "jQuery is not loaded".</p>
  
  <p>Can you let me know what I am missing?</p>
  
  <p>Edit:</p>
  
  <p>Thanks to comments, this is working:</p>
  
  <pre><code>    var script = document.createElement('script')
      script.type = 'text/javascript'
      script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js';
  script.onload = function(script){
              console.log(script + ' loaded!');
  if (window.jQuery) {  
      document.write('jQuery is loaded') 
  } else {
      document.write('jQuery is not loaded');
  }
          };
      document.head.appendChild(script);
  </code></pre>