I am trying to access a div id="mnuGrp" th开发者_高级运维at resides inside a child iframe(id="iframe2) from the parent window within the document.ready()
section but unsure how to access this child div in the parent inorder to apply fadein and fadeout calls.
I want to be used within the following call:
$(' ???? ').click(function(){ etc
where "????" is my means to access the child div within the iframe.
Since you're asking in a jQuery context specifically:
$(document).ready( function(){
$('#iframe2').contents().find('div#mnuGrp').fadeIn('slow');
// or whichever effect you prefer
});
Note that you will likely be constrained by the Same Origin Policy with respect to the main page and the frame source.
You can access the div in this way: window.frames[framename].document.getElementById("mnuGrp")
Everyone loves this contents().find()
not sure why.
jQuery isn't required. But if you wanted to use jQuery:
$("#mnuGrp", $("#iframe2")[0].contentWindow.document).click();
精彩评论