I have this kind of code:
iframe.html
:
<div id="w">
<div id="a">
...
</div>
<div id="b" style="display:none">
...
</div>
</div>
<a href="#" id="button" class="b open">Change</a>
main.html
:
...
<div id="con">
<iframe src="http://localhost/iframe.html" scrolling="no" id="myiframe">
<p>Your browser does not support iframes.</p>
</iframe>
</div>
<div id="show" style="display:none">
Hello WOrld!
</div>
My JavaScript inside the <iframe>
:
$(document).ready(function() {
$("a#button").click(function(){
if ($(this).hasClass('open')) {
$(this).removeClass('open');
$(this).addClass('close');
$('#a').fadeOut(200);
$("#b").fadeIn(200);
}else{
$("a#button").css({"margin-top":""});
$(this).removeClass('close');
$(this).addClass('open');
$("#b").fadeOut(200);
$('#a').fadeIn(200);
}
});
});
I try to insert this code in the <iframe>
JavaScript:
....
$("a#button").click(function(){
$("#show").css({"display":"block", "background":"green"});
....
}
However, it won't work because the JavaScript code is inside the <iframe>
and it cannot see the #show
<div>
.
Is there any way using JavaScript or jQuery that when I click the #button
in the <iframe>
that it will reflect the #show
<div>
?