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

HTML DOM offsetLeft property

HTML DOM offsetLeft property

Element Object Reference Element object

Example

Get the left offset of the div element:

var

testDiv

=

document

.

getElementById

(

"

test

"

)

;

document

.

getElementById

(

"

demo

"

)

.

innerHTML

=

testDiv

.

offsetLeft

;

Try it »


Definition and Usage

offsetLeft is a read-only property that returns the offset pixel value of the current element relative to the left boundary of the offsetParent node.

The return value includes:

Note: offsetParent The element is a reference to the nearest (in terms of containment hierarchy) positioned element or nearest element that contains it.

Tip: To get the top offset of the element, use offsetTop attribute.


Browser support

property
offsetLeft Yes Yes Yes Yes Yes

Syntax

element.offsetLeft 

Technical Details

Return Value: Returns an integer representing the left offset of the element, measured in pixels (px).

More examples

Example

Get the position of the div element:

var

testDiv

=

document

.

getElementById

(

"

test

"

)

;

var

demoDiv

=

document

.

getElementById

(

"

demo

"

)

;

demoDiv

.

innerHTML

=

"

offsetLeft:

"

testDiv

.

offsetLeft

"


offsetTop:

"

testDiv

.

offsetTop

;

Try it »


Element Object Reference Element object