Results 1 to 6 of 6

Thread: style.pixelLeft and style.left

  1. #1
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation style.pixelLeft and style.left

    Hello ,

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

    Thanks

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The main differences I can think of are:

    1. pixelLeft is proprietary to some (possibly only IE) browsers.
    2. pixelLeft isn't a style, it is a javascript setter/getter property of an element's style.
    3. pixelLeft assumes pixels as units and is an integer.
    4. 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.)
    5. 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:

    http://msdn.microsoft.com/workshop/a.../pixelleft.asp
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    So technically left and pixelleft are same apart from above differences ?

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

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

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for your help !

  6. #6
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    It would be a good idea to use [object].offsetLeft instead. Or parseInt([object].style.left).
    - Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •