English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
offsetLeftRead-only property to get the distance from the left outer border of the element to the left inner border of the offsetParent element (in pixels).
The returned value includes:
The left position and margin of the element
The left padding, scrollbar, and border of the offsetParent element
Note:ThisoffsetParentThe element is the closest parent element except for static.
To return the top position of the element, useoffsetTopProperty.
element.offsetLeft
var myBox = document.getElementById("box"); document.getElementById("result").innerHTML = myBox.offsetLeft;Test and See‹/›
All browsers fully support the offsetLeft property:
Property | |||||
offsetLeft | Yes | Yes | Yes | Yes | Yes |
Return Value: | A number representing the left 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:offsetTop property
HTML DOM Reference:offsetParent property