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

Steve James steve at epicunion.com
Fri Sep 23 13:29:37 CDT 2005


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

-- 

---

Steve James
Epic Union Designs
steve at epicunion.com
http://www.epicunion.com

"Web design, development, and hosting rolled up into one nifty package!" Epic Union.



More information about the thelist mailing list