Andrew Morris
Andrew Morris

Reputation: 1652

access div in iframe parent

I have a page which contains an iframe to another page, what I am looking for is to click something inside the iframe, which can then access or more specifically hide a div in the parent. I know some JQuery but for some reason just sit there blankly at the code editor when I try to write it on my own

Upvotes: 14

Views: 42964

Answers (3)

rekire
rekire

Reputation: 47995

If both pages are on the same (sub)domain you should be able to access the parent window with:

window.parent.document.getElementById('divId')

Well this is without jQuery but should work

Upvotes: 0

adeneo
adeneo

Reputation: 318372

$("#element-In-Iframe").on('click', function() {
    $('#element-in-parent-window', window.parent.document).hide();
});

FIDDLE

Upvotes: 2

ehmad11
ehmad11

Reputation: 1395

try this in iframe:

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

Upvotes: 34

Related Questions