469,936 Members | 2,466 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,936 developers. It's quick & easy.

W3C and style.left question

What I wanted was to get rid of offsetLeft and use "proper" way
instead....but when I do
document.getElementById('someDiv').style.left;
I keep getting empty string, unless I first set it manually (in CSS or js)
to some value...

if that is intended behavior(that is if I haven't f***d up something :) in
my code), and there is no offsetLeft property in W3C recommendation, what is
then "standard compliant" way to make browser calculate coordinates of some
tag on the page???

thanx in advance,
ivan


Jul 23 '05 #1
2 4679


ivanhoe wrote:
What I wanted was to get rid of offsetLeft and use "proper" way
instead....but when I do
document.getElementById('someDiv').style.left;
I keep getting empty string, unless I first set it manually (in CSS or js)
to some value...

if that is intended behavior(that is if I haven't f***d up something :) in
my code), and there is no offsetLeft property in W3C recommendation, what is
then "standard compliant" way to make browser calculate coordinates of some
tag on the page???


If you don't set the CSS inline style with CSS (e.g
<tag style="left: 100px;">
) or with script (e.g
elementObject.style.left = '100px';
) then it is correct that element.style.left returns an empty string as
element.style.cssProperty is not a cascaded computed CSS value but
simply a reflection of the inline style set on an element.
If you want a computed CSS value then with Netscape 6/7, Mozilla and
with Opera 7 you have DOM Level 2 support for
window.getComputedStyle(element, '').getPropertyValue('left')
however what browsers implement as offsetLeft follows different rules
compared to what getComputedStyle does so if your application works well
across browsers reading offsetLeft on abritrary elements you should in
my view stick with that. Or if you want to use getComputedStyle make
sure you test for your elements whether there are differences to
offsetLeft and adapt your script expressions if needed.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #2
DU
ivanhoe wrote:
What I wanted was to get rid of offsetLeft and use "proper" way
instead....but when I do
document.getElementById('someDiv').style.left;
I keep getting empty string, unless I first set it manually (in CSS or js)
to some value...

The css position property value defaults to static; it must be set to
relative or absolute or fixed, otherwise setting
ElemRef.style.left
to some value does not make any sense.
if that is intended behavior(that is if I haven't f***d up something :) in
my code), and there is no offsetLeft property in W3C recommendation,
True, there is no offsetLeft property in W3C recommendation. I think W3C
should have adopted the MSIE's DHTML object model. offset* values are
often very useful.

what is then "standard compliant" way to make browser calculate coordinates of some
tag on the page???

thanx in advance,
ivan


The coordinates you're referring to must be relative to some point of
reference. offset* values are relative to offsetParent element: that's
per definition. offsetParent is not part of the DOM Core. left, top,
bottom, right css properties (for abs. pos. elements) are relative to
the closest containing positioned element within the containment
hierarchy. There is a sharp distinction between the 2.

Interactive demo page on CSS positioning
http://www10.brinkster.com/doctorunc...sitioning.html

DU
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by TheKeith | last post: by
8 posts views Thread by TJ Walls | last post: by
33 posts views Thread by amerar | last post: by
1 post views Thread by amerar | last post: by
83 posts views Thread by rahul8143 | last post: by
2 posts views Thread by Steve Richter | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.