Simranjeet
Simranjeet

Reputation: 178

How to apply css with jquery outside from iframe

I am using iframe popup and i want to change something outside of iframe with jquery from iframe ?

this need to be done with jquery.

code like this

<iframe> <div  id="change">Change css</div> </iframe>
<div class="outer-div"> Text goes here </div>

<script>
$("#change").live('click', function(){
           $('#outer-div').css('display','none');
});
<script>

i want to hide of outer div click on iframe inner div

thanks Simranjeet singh

Upvotes: 0

Views: 941

Answers (1)

Pat Dobson
Pat Dobson

Reputation: 3299

This is some code that has worked for me.

Assuming that the iFrame is within the same domain as it's parent, try this:

// -- Find the PARENT of the iFrame that this script runs in
var $topLevel = $(window.parent.document, window.parent.document);

If you then use $topLevel as a starting point for your jQuery it should work.

Be aware that this codes works alright in modern browsers but doesn't seem to operate in IE8 (and untested below IE8)

Upvotes: 1

Related Questions