2

Need get access to element inside in frame inside in inframe with jQuery.

I have this struct:

<iframe id="frame1">
  <frameset id="frameset">
    <frame id="frame2"> <div id="exampleDiv">text</div> </frame>
  </frameset>
</iframe>

and script:

$("#frame1 #frameset #frame2").load(function () {
    $('#exampleDiv').hide();
});

but this script is not working

Temaska
  • 307
  • 1
  • 3
  • 13
  • 4
    Yo dawg, I heard you liked frames, so I put a frame in your iframe, so you can frame while you're framin' – j08691 Jun 12 '12 at 16:50
  • 2
    This may help you: http://stackoverflow.com/questions/2921957/how-to-access-frame-not-iframe-contents-from-jquery or this http://stackoverflow.com/questions/2941855/jquery-access-frame-in-nested-frameset :) – doptrois Jun 12 '12 at 17:00

1 Answers1

1

you should use the jquery content() to retrieve the content of an iframe then use the .find() method but the document in the frame should be in the same domain that the parent document.

in this case :

 $("#frame1").contents().find("#exampleDiv").hide()
Chuck Mah
  • 638
  • 6
  • 9
  • 2
    `alert($("#frame1").contents().find("#exampleDiv").html());`is null; `alert($("#frame1").contents().find("#frame2").contents().find("#exampleDiv").html());` is null :( – Temaska Jun 12 '12 at 17:28
  • `$($("#frame1").contents().find("#frame2")[0].contentDocument).find('#exampleDiv').html()` <- The internet is horrible. – Christian Apr 05 '18 at 07:01