How to access DIV inside iframe from parent

I am trying to access the div id = "mnuGrp", which is inside the child iframe (id = "iframe2) from the parent window in the section document.ready()but not sure how to access this child div in the parent order of Fadein and Fadeout calls.

I want to be used in the following call:

$(' ???? ').click(function(){ etc

where is "????" my facilities for accessing a div child inside an iframe.

+3
source share
3 answers

Since you are requesting a specific jQuery context:

$(document).ready( function(){
    $('#iframe2').contents().find('div#mnuGrp').fadeIn('slow');
    // or whichever effect you prefer
});

Please note that you are likely to be limited to policies of the same origin with respect to the main page and frame source.

+7

div : window.frames[framename].document.getElementById("mnuGrp")

+3

Everyone loves it is contents().find()not sure why.
jQuery is not required. But if you want to use jQuery:

$("#mnuGrp", $("#iframe2")[0].contentWindow.document).click();
+1
source

Source: https://habr.com/ru/post/1748954/


All Articles