RE: [cssom-view] Why is body's offsetParent null ?

> So the behavioural difference between body and other elements is
> introduced because of MSIE but the Web is full of the following
> script:
> var t = 0;
> var p = myElement;
> while (p) {
>    t += p.offsetTop;
>    p =  p.offsetParent;
> }
> // use t

When you want to find the offset all the way up to the top then
actually both IE and CSSOM gets it right. I made a comparison table
here a while ago:

Though, the CSSOM scheme will break down if you want to know the 
offset to the body element as there is no way to get at this 

In particular, as Garrett pointed out, this offset is available in all
browsers except Opera (and CSSOM) when using position:relative on the 
body element:

> Because of the change you introduce saying document.body.offsetTop
> is now always zero

This is actually part of a long discussion Garrett/dhtmlkitchen and I 
have had with Anne about the suggested offset* algorithm.
You can find parts of it here:

Best regards
Mike Wilson

Received on Wednesday, 23 April 2008 10:29:19 UTC