English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM offsetParent attribute

HTML DOM Element Object

offsetParentIt is a read-only property that returns a reference to the nearest (in terms of the containment hierarchy) positioning element that contains the element, or the nearest table, td, th, or body element. When the element's style.display is set to "none", offsetParent returns null.

Note: The offsetParent is very useful because offsetLeftandoffsetTop are all relative to their padding boundary.

When the element is set to display="none", offsetParent returnsnull.

Syntax:

element.offsetParent
var myBox = document.getElementById("box");
document.getElementById("result").innerHTML = myBox.offsetParent;
Test and See‹/›

Browser Compatibility

All browsers fully support the offsetParent property:

Property
offsetParentYesYesYesYesYes

Technical Details

Return Value:A Node object representing the nearest parent element, whose position is not static
DOM Version:CSS Object Model (CSSOM)

Related References

HTML DOM Reference:offsetHeight Property

HTML DOM Reference:offsetWidth Property

HTML DOM Reference:offsetTop Property

HTML DOM Reference:offsetLeft Property

HTML DOM Element Object