Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide a div in the parent of an iframe

Tags:

jquery

iframe

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.

like image 850
GluePear Avatar asked Oct 25 '25 23:10

GluePear


1 Answers

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/

like image 132
Jason P Avatar answered Oct 29 '25 18:10

Jason P