title: How may I reference the script tag that loaded the currently-executing script?
body: <p>How can I reference the script element that loaded the javascript that is currently running?</p>
  
  <p>Here's the situation. I have a "master" script being loaded high in the page, first thing under the HEAD tag.</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
  &lt;head&gt;
  &lt;script type="text/javascript" src="scripts.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>There is a script in "scripts.js" which needs to be able to do on-demand loading of other scripts. The normal method doesn't quite work for me because I need to add new scripts without referencing the HEAD tag, because the HEAD element hasn't finished rendering:</p>
  
  <pre><code>document.getElementsByTagName('head')[0].appendChild(v);
  </code></pre>
  
  <p>What I want to do is reference the script element that loaded the current script so that I can then append my new dynamically loaded script tags into the DOM after it.</p>
  
  <pre><code>&lt;script type="text/javascript" src="scripts.js"&gt;&lt;/script&gt;
  loaded by scripts.js--&gt;&lt;script type="text/javascript" src="new_script1.js"&gt;&lt;/script&gt;
  loaded by scripts.js --&gt;&lt;script type="text/javascript" src="new_script2.js"&gt;&lt;/script&gt;
  </code></pre>