Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the different between style.left and element.offsetLeft

Tags:

javascript

dom

who can tell me what's the different between style.left and element.offsetLeft, is it same?

like image 534
user2155362 Avatar asked May 28 '13 02:05

user2155362


3 Answers

element.offsetLeft Returns the number of pixels that the upper left corner of the current element is offset to the left within the offsetParent node.

elem.style.left it's a get of property left of style attribute

like image 152
PSR Avatar answered Oct 15 '22 02:10

PSR


You can set the style.left - it is user definable and can even remain blank, while offsetLeft is always read-only and always has a value - current position.

like image 5
Yuriy Galanter Avatar answered Oct 15 '22 02:10

Yuriy Galanter


element.offsetLeft returns the distance from the left edge of the node to the parent node in pixels.

style.left is the CSS Style for the node, and may be in any of these formats: CSS Unit Formats

like image 1
Isaac Avatar answered Oct 15 '22 02:10

Isaac