AlexJaa
AlexJaa

Reputation: 389

working iframe with jquery

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

Answers (4)

Zaheer Ahmed
Zaheer Ahmed

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

Shyam
Shyam

Reputation: 792

Try : parent.$('#test').hide();

Upvotes: 0

Anup
Anup

Reputation: 9738

You can use this :-

$('#test', window.parent.document).hide();

Upvotes: 1

adeneo
adeneo

Reputation: 318182

$(document).ready(function(){
    $('#btn').click(function(){
        $(window.parent.getElementById('test')).hide();
    });
});

Upvotes: 1

Related Questions