rocky
rocky

Reputation: 339

Jquery: Unable find elements inside iframe

i have page using iframe:

page a.html:

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

now i want to get elements in iframe, so i try:

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

but result return is: <head></head><body></body>, don't have content in head or body. i need a help

Upvotes: 5

Views: 9311

Answers (1)

Paul Rad
Paul Rad

Reputation: 4882

Because your frame is not again loaded..

Try

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

Upvotes: 12

Related Questions