2

How to find the most parent body element of a document, if you're using a lot of frames. Inside a iframe that also is in a few iframes, I want to call a function for the most upper document body.

The following works, except that you have to count for the parents each time.

$(parent.parent.parent.parent.document.body).function('loading');

Isn't there something like this?;

$(parentOfAllParents.document.body).function('loading');
user1867254
  • 462
  • 2
  • 7
  • 18

2 Answers2

5

This does the trick from any iframe: top.window.document.body

Teemu
  • 22,058
  • 6
  • 53
  • 101
5

Use window.top.

Specification is here.

Alexander
  • 23,094
  • 11
  • 58
  • 74
Terry Horner
  • 477
  • 5
  • 16