title: Dynamically Add js file at the end of the page using javascript?
body: <p>I want to add one js file at the bottom of the page before <code>&lt;/body&gt;</code> tag.</p>
  
  <p>I am trying one format. But its not working properly.</p>
  
  <p>My code </p>
  
  <pre><code>var url = 'sample.js';
  var script = document.createElement("script");
  script.type = "text/javascript";
  script.src = url;
  document.getElementsByTagName('body')[0].appendChild(script);
  </code></pre>
  
  <p>But its not working. </p>
  
  <p>Now i check  </p>
  
  <pre><code>var x = document.getElementsByTagName('body');
  alert(x.length);
  </code></pre>
  
  <p>its shows <code>0</code></p>
  
  <p>How can i add this js file into my bottom of the page. Please advise</p>