HTML DOM offsetParent Property

元素对象参考手册Element Object

Examples

Get the nearest ancestor element of a div:

var testDiv = document.getElementById("test"); document.getElementById("demo").innerHTML = testDiv.offsetParent;

Try it Yourself »

Definition and Usage

offsetParent is a read-only property that gets the nearest positioned ancestor element.

Note:offsetParent is used foroffsetLeftandoffsetTopthe property.

Tip:When the element's style.display is set to "none", offsetParent returns null.


Browser Support

Property
offsetParent Yes Yes Yes Yes Yes

Syntax

element.offsetParent 

Technical Details

Return Value: A node object representing the nearest ancestor element.


元素对象参考手册Element Object

Other Extensions