View Full Version : style.pixelLeft and style.left

03-16-2007, 08:20 AM
Hello :),

Can anyone please tell me what is the difference between left and pixelLeft in the style propertie ?

Thanks :)

03-16-2007, 08:47 AM
The main differences I can think of are:

pixelLeft is proprietary to some (possibly only IE) browsers.
pixelLeft isn't a style, it is a javascript setter/getter property of an element's style.
pixelLeft assumes pixels as units and is an integer.
left is used by virtually all browsers and to work generally (but not always) requires that the units be specified (left:20px; or left:10%; etc.)
left is a style property as well as a javascript setter/getter property of an element's style. It is a string not an integer.

See also:


03-16-2007, 04:21 PM
So technically left and pixelleft are same apart from above differences ?

03-16-2007, 04:39 PM
Pretty much but, the differences are significant. Since everything that can be accomplished with pixelLeft can be done with left and/or other cross browser techniques and, left works in all browsers, I'd just forget about pixelLeft unless it came in handy for something that needed to be IE only and didn't cause other problems.

BTW - This works in IE 7, Opera 9.01 but, not in FF:

<div style="position:relative;left:10px;" onclick="alert(this.style.pixelLeft);">Hi</div>

03-16-2007, 05:45 PM
Thanks for your help :) !

03-16-2007, 06:24 PM
It would be a good idea to use [object].offsetLeft instead. Or parseInt([object].style.left).