title: Dynamically adding a script tag to page
body: <p>I am trying to add a script to dom using insertBefore.</p>
  
  <p>When running the commands through console, the script is executed as expected, but when the same code piece is run via code, it refuses to execute.</p>
  
  <p>This is the code I am using.</p>
  
  <pre><code>var el = document.getElementsByTagName('div')[0];
  var s = document.createElement('script');
  s.text = 'alert("abc");'
  el.parentNode.insertBefore(s, el.nextSibling)
  
  
  
  el.parentNode.replaceChild(s.childNodes[0], el);
  el = s.childNodes[0];
  for(var i = s.childNodes.length - 1; i &gt;= 0 ; i--)
      el.parentNode.insertBefore(s.childNodes[i], el.nextSibling);
  </code></pre>
  
  <p>This is adding the script to the DOM but not executing it.a</p>