Get the offsetLeft position of "myDIV":
const element = document.getElementById("myDIV");
let pos = element.offsetLeft;
Try it Yourself »
Get the positions of "myDIV":
const element = document.getElementById("myDIV");
let pos1= element.offsetTop;
let pos2= element.offsetLeft;
Try it Yourself »
The offsetLeft
property returns the left position (in pixels) relative to the parent.
The returned value includes:
The offsetLeft
property is read-only.
All block-level elements report offsets relative to the offset parent:
The offset parent is the nearest ancestor that has a position other than static.
If no offset parent exists, the offset is relative to the document body.
Return the left offset position:
element.offsetLeft
Type | Description |
Number | The left position of the element, in pixels. |
element.offsetLeft
is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!