Sorry this answer is not in jquery (I struggled with something similar over the last couple of hours with the prototype).
Basically, the best answer from bobince is quite useful, however you can reassign the body of the document whose trick finds it.
This is a prototype, but you realized
body = $("content").ancestors().last().children[1];
If the content is a specific element on the page that you can find using regular selectors, any of them can be used, it does not really matter, from there you go to the top, and then down to the body element.
Hope this helps, for example, I said that my problem was only similar, not sure how it would suit you, but I hope this at least gives someone an idea.
source share