title: "Cannot call method 'oEmbed' of null" when embedding Soundcloud player in dynamically generated Div
body: <p>Using the Soundcloud JavaScript API, I want to dynamically generate a page of player widgets using track search results.  My code is as follows:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script src="http://connect.soundcloud.com/sdk.js"&gt;&lt;/script&gt;
  
  &lt;script&gt;
  function makeDivsFromTracks(tracks,SC)
  {
   var track;
   var permUrl;
   var newDiv;
   for(var ctr=0;ctr&lt;tracks.length;ctr++)
   {
    newDiv=document.createElement("div");
    newDiv.id="track"+ctr;
    track=tracks[ctr];
    SC.oEmbed(track.permalink_url,{color:"ff0066"},newDiv);
    document.body.appendChild(newDiv);
   }
  }
  &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;script&gt;
  SC.initialize({
      client_id: 'MY_CLIENT_ID'
  });
  SC.get('/tracks',{duration:{to:900000},tags:'hitech',downloadable:true},
          function(tracks,SC)
          {
           makeDivsFromTracks(tracks,SC);
          });
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>When I load this, the <code>SC.oEmbed()</code> call throws an error:</p>
  
  <pre><code>Uncaught TypeError: Cannot call method 'oEmbed' of null 
  </code></pre>
  
  <p>which would seem to indicate that either the <code>div</code>s aren't being generated or the search results aren't being returned, but if I remove the <code>SC.oEmbed()</code> call and replace it with:</p>
  
  <pre><code>newDiv.innerHTML=track.permalink_url;
  </code></pre>
  
  <p>then I get a nice list of the URLs for my search results.</p>
  
  <p>And if I create a widget using a static <code>div</code> and static URL, e.g.</p>
  
  <pre><code>&lt;body&gt;
  &lt;div id="putTheWidgetHere"&gt;&lt;/div&gt;
  &lt;script&gt;
  SC.initialize({
      client_id: 'MY_CLIENT_ID'
  });
  SC.oEmbed("http://soundcloud.com/exampleTrack", {color: "ff0066"},  document.getElementById("putTheWidgetHere"));
  &lt;/script&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>then that works fine as well.  So what's the problem with my <code>oEmbed()</code> call with these dynamically created elements?</p>