Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM offsetParent property

HTML DOM offsetParent property

Element Object Reference Element object

Example

Get the nearest ancestor element of the div:

var

testDiv

=

document

.

getElementById

(

"

test

"

)

;

document

.

getElementById

(

"

demo

"

)

.

innerHTML

=

testDiv

.

offsetParent

;

Try it »


Definition and Usage

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

Note: offsetParent is used to offsetLeft and offsetTop attribute.

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 Reference Element object