English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
element.offsetParent
var myBox = document.getElementById("box"); document.getElementById("result").innerHTML = myBox.offsetParent;Test and See‹/›
All browsers fully support the offsetParent property:
Property | |||||
offsetParent | Yes | Yes | Yes | Yes | Yes |
Return Value: | A Node object representing the nearest parent element, whose position is not static |
---|---|
DOM Version: | CSS Object Model (CSSOM) |
HTML DOM Reference:offsetHeight Property
HTML DOM Reference:offsetWidth Property
HTML DOM Reference:offsetTop Property
HTML DOM Reference:offsetLeft Property