...">

JQuery: cannot find elements inside iframe

I have a page using iframe:

a.html page :

<div id="results">
  <iframe src="../b.aspx"></iframe>
</div>

now I want to get the elements in an iframe, so I'm trying:

<script type="text/javascript">
        jQuery(document).ready(function($) {
            var tmp = $('#results iframe').contents().find('html').html();
            alert(tmp);
        });
</script>

but the return: result <head></head><body></body>has no content in the head or body. I need help

+4
source share
1 answer

Since your frame is not loaded again.

Try

$("#YOURFRAME").load(function (){
  var tmp = $('#results iframe').contents().find('html').html();
  alert(tmp);
});
+10
source

All Articles