Reputation: 7715
I'm trying to hide a <div>
in the parent of an iframe when that iframe loads. The iframe and parent are in the same domain.
Following the accepted answer to this question, I have this code in the iframe:
<script type="text/javascript" src="jquery-1.10.1.min.js"></script>
<script type="text/javascript">
$(document).load(function(){
$('#remove_me', window.parent.document).hide();
});
</script>
Upon loading the iframe, the <div>
is not hidden, though. Am I missing something obvious? Thanks in advance.
Upvotes: 4
Views: 6939
Reputation: 28114
You also need to make sure that the parent document is loaded. Try this:
$(window).load(function(){
$(window.parent).load(function(){
$('#remove_me', window.parent.document).hide();
});
});
Upvotes: 1
Reputation: 27012
Try $(document).ready(...)
instead of $(document).load(...)
. The load
event is for "any element associated with a URL: images, scripts, frames, iframes, and the window object."
http://api.jquery.com/load-event/
Upvotes: 4