title: Why is iframe.contentWindow == null?
body: <p>I use the following code to dynamically create an iframe.</p>
  
  <pre><code>var iframe_jquery = $("&lt;iframe&gt;")
      .addClass("foo")
      .appendTo(container); // container is a jQuery object containing a &lt;div&gt; which already exists
  </code></pre>
  
  <p>Then, I want to access its contentWindow, but it's null:</p>
  
  <pre><code>var iframe = iframe_jquery.get(0);
  if (iframe){ // iFrame exists
      console.log(iframe.contentWindow); // Prints "null"
      var doc = iframe.contentWindow.document; // NullpointerException
  }
  </code></pre>
  
  <p>So I thought: "Maybe the iframe isn't ready yet?" So I tried:</p>
  
  <pre><code>iframe_jquery.ready(function(){
      var iframe = iframe_jquery.get(0);
      console.log(iframe.contentWindow); // Prints "null"
      var doc = iframe.contentWindow.document; // NullpointerException
  });
  </code></pre>
  
  <p>Same result.</p>
  
  <p><strong>What's wrong?</strong></p>