DOM Extensions - Usage

dom_extensions.js defines the following functions:

getOffsetLeft()

Synopsis

getOffsetLeft(element, deep)

Arguments

element

Reference to an HTML element.

deep

An optional boolean to indicate whether to get the offset from the document root as opposed to the offset parent; true uses the document root, false uses the offset parent. Defaults to false.

Returns

The horizontal distance to the element from either the document root or the element's offset parent in pixels.

Description

getOffsetLeft() gets the element's offset from either it's offset parent (which behaves like element.offsetLeft) or the document root (which avoids browser-specific offset parent issues). The document root option is by far the more useful. Note that on IE Mac, the document's padding is not accounted for.

getOffsetTop()

Synopsis

getOffsetTop(element, deep)

Arguments

element

Reference to an HTML element.

deep

An optional boolean to indicate whether to get the offset from the document root as opposed to the offset parent; true uses the document root, false uses the offset parent. Defaults to false.

Returns

The vertical distance to the element from either the document root or the element's offset parent in pixels.

Description

getOffsetTop() gets the element's offset from either it's offset parent (which behaves like element.offsetTop) or the document root (which avoids browser-specific offset parent issues). The document root option is by far the more useful. Note that on IE Mac, the document's padding is not accounted for.

More about this script

Related to this script

Licensing

This script is released under a Creative Commons License.