3

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
  • 492
  • 2
  • 7
  • 18

2 Answers2

5

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

Teemu
  • 22,918
  • 7
  • 53
  • 106
5

Use window.top.

Specification is here.

Alexander
  • 23,432
  • 11
  • 63
  • 73
Terry Horner
  • 497
  • 6
  • 16