[thelist] Getting position with Javascript without setting them in Javascript

VOLKAN ÖZÇELİK volkan.ozcelik at gmail.com
Fri Sep 23 15:31:16 CDT 2005


>I have always been under the impression that even if you
>define a position or dimension in CSS, you can't access it in Javascript
>via the DOM. I am not sure why though.

Actually you do access to the style. However if you do not assign the
top or left value explicitly DOM returns "auto" as per the value.

http://www.sarmal.com/sardalya/testcase/StyleManager_Test.html

(note that the last line on the test results layer displays "auto" for
the retrieved "top" value since it is not explicitly defined in the
CSS.)

HTH,
Volkan.


2005/9/23, Peter Brunone (EasyListBox.com) <peter at easylistbox.com>:
> Hi Steve,
>
>   I'm not sure what the posLeft style attribute is, but if you want to find the true position of anything on the page, I suggest PPK's article on the subject:
>
> http://www.quirksmode.org/js/findpos.html
>
>   For what it's worth, I've encountered similar problems in IE when trying to get the left or top properties when they haven't been specified...
>
> Cheers,
>
> Peter
>
> From: Steve James steve at epicunion.com
>
> So this has always stumped me and I'm not sure if there is a solution:
>
> I have XHTML page with nested DIVs. Everything is relative and nothing
> is absolutely positioned. I need to use Javascript to get positions of
> DIVs on the page, however I am getting nothing back UNLESS I specify
> the positions first using Javascript. However, this defeats the whole
> purpose of "hey, what position is that DIV?" if I have to specify where
> it is first. I have always been under the impression that even if you
> define a position or dimension in CSS, you can't access it in Javascript
> via the DOM. I am not sure why though.
>
> So something like this never gives me a result:
> alert(document.getElementById('theNav').style.posLeft); //alerts back
> nothing/blank
>
> However, this does:
> document.getElementById('theNav').style.posLeft = '100px';
> alert(document.getElementById('theNav').style.posLeft); //alerts back 100px
>
> Thanks for any support or explanations.
>
> -Steve
> --
>
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !
>


More information about the thelist mailing list