title: better way to create dynamic iframes in jQuery?
body: <p>So I have the following code which is doing a setInterval until the iframe is available to be written to.</p>
  
  <pre><code>$( '#testdiv').append( $('&lt;iframe id="testiframe"/&gt;') );
  var t = setInterval(function(){
      if(document.getElementById('testiframe') !== 'undefined'){
          clearInterval(t);
          $('#testiframe').contents().find('body').append('asd'); 
      }
  }, 15);
  </code></pre>
  
  <p>Basically what happens is that jQuery creates the iframe element and loads it into the DOM. However, the iframe isn't available immediately so additional jQuery calls that are coded to happen right afterwords. With this chunk of code, it does a simple interval check until the new iframe is available, then writes 'asd' to its contents.</p>
  
  <p>I've spent about an hour trying out different methods of chaining methods to the iframe creation, but nothing really works. It all seems a matter of timing. I tried $('#testiframe').live('load',function(){}); and that doesn't work at all.</p>
  
  <p>So does anyone have a cleaner recommendation on this?</p>