PDA

View Full Version : jQuery - Change content of an element



RichardG
01-29-2011, 06:42 PM
I'm trying to change the content of an element from withing an iframe.

If I use this:

$('body').replaceWith("hi");
then the content of the iframe is replaced correctly.

However when I try to access the parent document it doesn't work. I've been using this code:

$('body', window.parent.document).replaceWith("hi");

What is the correct way to do this? I've tried many tutorials online but nothing seems to be working.

ggalan
01-29-2011, 07:48 PM
does this help?
http://stackoverflow.com/questions/726816/how-to-write-this-in-jquery-window-parent-document-getelementbyidparentprice

RichardG
01-29-2011, 08:02 PM
Hi no it didn't. I tried using:

$('#menu', window.parent.document).html("hi");

My understanding is that this code would go to the top parent and look for the element with ID 'menu' and would then replace it's contents with "hi".

Is that right?

ggalan
01-30-2011, 03:35 PM
I guess the iframe behaves differently