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

Peter Brunone (EasyListBox.com) peter at easylistbox.com
Fri Sep 23 14:40:41 CDT 2005


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


More information about the thelist mailing list