English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
offsetTopIt is a read-only property that returns the distance from the top inner padding of the current element to its offsetParent element.
The returned value includes:
The top position and margin of the element
The top padding, scrollbar, and border of the offsetParent element
Note:ThisoffsetParentThe element is the nearest parent element whose position is not static.
To return the left position of the element, useoffsetLeftProperty.
element.offsetTop
var myBox = document.getElementById("box"); document.getElementById("result").innerHTML = myBox.offsetTop;Test and See‹/›
All browsers fully support the offsetTop property:
Property | |||||
offsetTop | Yes | Yes | Yes | Yes | Yes |
Return Value: | A number representing the top position of the element, in pixels |
---|---|
DOM Version: | CSS Object Model (CSSOM) |
Return the position of the DIV element:
var myBox = document.getElementById("box"); var x = document.getElementById("result"); x.innerHTML = "offsetLeft: " + myBox.offsetLeft + "<br>offsetTop: " + myBox.offsetTop;Test and See‹/›
HTML DOM Reference:offsetHeight property
HTML DOM Reference:offsetWidth property
HTML DOM Reference:offsetLeft property
HTML DOM Reference:offsetParent property