title: Same domain : How to access iframe content using jquery or javascript
body: <p>I have a dynamic iframe created in my page and loading html content inside the iframe but using jquery, not able to access the html content inside the iframe.</p>
  
  <p>Based on the results over the website found below two but not applicable in my case</p>
  
  <ol>
  <li>iframe is having the URL of same domain as i am using /testhtm.html in the src and loading it.</li>
  <li>iframe is getting loaded up because i have alerted when the iframe gets loaded up after that i fire my event</li>
  </ol>
  
  <p>Getting an error in browser while on console trying to access the iframe:</p>
  
  <blockquote>
    <p>Error: Permission denied to access property 'document'<br>
    document.getElementById('testiframe').contentWindow.document.body.inne...</p>
  </blockquote>
  
  <p>Trying to access my div which is inside iframe:</p>
  
  <pre><code>$("#testFrame").contents().find("#myDiv");
  </code></pre>
  
  <p>iframe code:</p>
  
  <pre><code>var ifr = $('&lt;iframe/&gt;', {
      id: 'testiframe',
      name: 'genericFrame',
      src: '/testhtml.html?' + serializeForm(params),
      style: 'display: none',
      load: function(){
          alert('iframe loaded !');
      }
  });
  $('#overlay').html(ifr); // Attaching it to overlay so that iframe loads in a lightbox
  </code></pre>
  
  <p>Any suggestions or tricks to actually access the div and show it?</p>
  
  <h2>UPDATE:</h2>
  
  <p>I am getting something using javascript:</p>
  
  <pre><code>var ifrBody = document.getElementById('testiframe').contentWindow;
  
  returns me window object with content but i am unable to access it
  </code></pre>
  
  <p>but using jquery it throws error:</p>
  
  <pre><code> var iBody = $("#testFrame").contents().find("body");
  
  Error: Permission denied to access property 'document'
  </code></pre>