Get the offsetParent of "myDIV":
let node = document.getElementById("myDIV").offsetParent;
Try it Yourself »
The offsetParent
property returns the nearest ancestor that has a position other than static.
The offsetParent
property returns null
if the element is not visible (display="none").
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 parent is the document body.
element.offsetParent
Type | Description |
Node | The nearest positioned ancestor. |
element.offsetParent
is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!