Results 1 to 4 of 4

Thread: jQuery - Change content of an element

  1. #1
    Join Date
    Jan 2011
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default jQuery - Change content of an element

    I'm trying to change the content of an element from withing an iframe.

    If I use this:
    Code:
    $('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:
    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.

  2. #2
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

  3. #3
    Join Date
    Jan 2011
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Hi no it didn't. I tried using:
    Code:
    $('#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?

  4. #4
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    I guess the iframe behaves differently

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •