offsetLeft vs left

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

offsetLeft vs left

Post by JellyFish »

What's the diference between element.style.left and element.offsetLeft?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

One is CSS, the other is the actual position.
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

Aren't they both actual positions? I meant what diferent uses do they have? Why is there two of the same properties?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

They aren't the same. As I've already said, one is CSS, the other is the actual position.
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

*sigh*... What diference do they have programmaticly?

Edit: Man, do you not get what I'm asking? Yeah ones CSS and the other isn't. But what does that tell me?

Edit2: I noticed that CSS' left is 0 even if the element is centered in the screen because the attribute was not set. I assume offsetLeft is not the same in that way?
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

"One is CSS left" means the amount that was specified as "left" in "CSS". Not usually that useful.

The other is problematic at best. If it's important to have a cross-browser solution that works, use prototype. (or at least learn from the offset code they use)
Post Reply