A
amattie
Anyone know what the specific difference is between the offsetParent
and parentNode properties of a DOM element are?
Mozilla's docs on the DOM element
(http://developer.mozilla.org/en/docs/DOM:element) don't really
indicate much of a difference, but whatever the difference is is really
screwing me up in one of my projects. On a specific div node nested
within a whole bunch of other div nodes in the DOM, the parentNode
property evaluates to the actual parent node, whereas offsetParent
evaluates to null. This doesn't really affect me, but when I go to
clone the node to append it to clone's real parent for another purpose,
the parentNode of the new clone node remains the actual parent I
appended it to whereas the offsetParent becomes the HTML body element!
(Also, just so you know, I checked the parentNode / offsetParent before
I cloned it to make sure it wasn't a problem with the clone procedure.)
The reason I need the offsetParent instead of the parentNode is because
offsetTop for each of my new cloned nodes is screwed up. Because
offsetParent is the body node, offsetTop gives me the pixel count
between the top of the browser and the element itself. I need the
offsetTop of the container element, the _real_ parent node.
There's nothing really special about this node as far as I can tell.
I'm using FF 1.5.0.7 and a XHTML 1.0 transitional doctype. I haven't
tested any other elements on the DOM for this weird behaviour, and I
haven't tried it in other browsers yet. I've done things similar to
this before though, and I've never had problems with it. Any ideas of
how I can fix this problem, or where I can look for more info? Thanks.
Andrew
and parentNode properties of a DOM element are?
Mozilla's docs on the DOM element
(http://developer.mozilla.org/en/docs/DOM:element) don't really
indicate much of a difference, but whatever the difference is is really
screwing me up in one of my projects. On a specific div node nested
within a whole bunch of other div nodes in the DOM, the parentNode
property evaluates to the actual parent node, whereas offsetParent
evaluates to null. This doesn't really affect me, but when I go to
clone the node to append it to clone's real parent for another purpose,
the parentNode of the new clone node remains the actual parent I
appended it to whereas the offsetParent becomes the HTML body element!
(Also, just so you know, I checked the parentNode / offsetParent before
I cloned it to make sure it wasn't a problem with the clone procedure.)
The reason I need the offsetParent instead of the parentNode is because
offsetTop for each of my new cloned nodes is screwed up. Because
offsetParent is the body node, offsetTop gives me the pixel count
between the top of the browser and the element itself. I need the
offsetTop of the container element, the _real_ parent node.
There's nothing really special about this node as far as I can tell.
I'm using FF 1.5.0.7 and a XHTML 1.0 transitional doctype. I haven't
tested any other elements on the DOM for this weird behaviour, and I
haven't tried it in other browsers yet. I've done things similar to
this before though, and I've never had problems with it. Any ideas of
how I can fix this problem, or where I can look for more info? Thanks.
Andrew