Reputation: 389
I want to do some jquery script using button clicked inside an iframe
and the output is outside an iframe....Is it possible??? my main html look like this:
<html>
<head></head>
<body>
<div id="test" >test</div>
<iframe width="100px" height="100px" src="test.php" ></iframe>
</body>
</html>
and for test.php:
<html>
<head>
<script src="jquery.min.js" ></script>
<script>
$(document).ready(function(){
$('#btn').click(function(){
$('#test').hide(); // i want to hide this whenever a button with id btn inside and iframe is triggered
});
});
</script>
</head>
<body>
<button id='btn' >click</button>
</body>
</html>
that's the way I do it but this doesn't work. Thanks for any ideas... :)
Upvotes: 0
Views: 48
Reputation: 28548
You can use window.parent
if your iframe and your current page are of same domain else it won't work.
Upvotes: 1
Reputation: 318182
$(document).ready(function(){
$('#btn').click(function(){
$(window.parent.getElementById('test')).hide();
});
});
Upvotes: 1