title: Count number of async scripts in the DOM
body: <p>I have a script <code>script.js</code> that calls in advertisements into the DOM. It is invserted after <code>#closeImage</code> if some test is true:</p>
  
  <pre><code>&lt;div id="overlay"&gt;
      &lt;img id="closeImage" src="close100x100.png"&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>If the test is true I call my script. </p>
  
  <pre><code>if (test) {
           var script = document.createElement('script');
           script.type = 'text/javascript';
           script.src = 'script.js';
           $("#closeImage").append(script);
  </code></pre>
  
  <p><code>script.js</code> might not find an advertisement. In this case from within <code>script.js</code>,  <code>script01.js</code> which will be inserted into the DOM to look for different advertisements. If nothing is found <code>script03.js</code> will be called from within <code>script02.js</code> and so my <code>div</code> might end looking like this:</p>
  
  <pre><code>&lt;div id="overlay"&gt;
      &lt;img id="closeImage" src="close100x100.png"&gt;
      &lt;script src="script.js"&gt;&lt;/script&gt;
      &lt;script src="script01.js"&gt;&lt;/script&gt;
      &lt;script src="script02.js"&gt;&lt;/script&gt;
      &lt;!-- actual banner html --&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Only the first script is being inserted by the original <code>document.createElement()</code>. How do I count the number of scripts in <code>#overlay</code>? - This did not work:</p>
  
  <pre><code>$(document).ready(function () { 
    var loaded = $('div#ADF_overlay script').length;
  });
  </code></pre>
  
  <p><strong>EDIT</strong> (Restated the problem differently based on feedback)</p>