HighDots Forums  

how to retrieve DIV position???

Javascript JavaScript language (comp.lang.javascript)


Discuss how to retrieve DIV position??? in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Billy
 
Posts: n/a

Default how to retrieve DIV position??? - 02-04-2004 , 02:24 PM






Hi, I was wondering how to retrieve the cordinates of a CSS layer with
javascript.

I set the layer cordinates as like this in the header:

<style type="text/css">
..classID {
position: absolute;
left: 2px;
top: 100px;
}
</style>

then in the body I have:

<div id="layerID" class="classID">
some html and text
</div>

The layer positions properly so I know that works.

and then in a javascript function I try to retrieve the cordinates by:

toppos = document.getElementById("layerID").style.top;
leftpos = document.getElementById("layerID").style.left;

but leftpos and toppos always come back blank.


Thanks in advance!
Billy



Reply With Quote
  #2  
Old   
Bas Cost Budde
 
Posts: n/a

Default Re: how to retrieve DIV position??? - 02-04-2004 , 06:16 PM






Billy wrote:

Quote:
Hi, I was wondering how to retrieve the cordinates of a CSS layer with
javascript.
Is getComputedStyle something for you? Sample article:

http://www.csie.ntu.edu.tw/~b7506051...examples7.html

--
Bas Cost Budde
http://www.heuveltop.nl/BasCB



Reply With Quote
  #3  
Old   
Billy
 
Posts: n/a

Default Re: how to retrieve DIV position??? - 02-05-2004 , 01:34 AM



Thanks!

"Bas Cost Budde" <bas (AT) heuveltop (DOT) org> wrote

Quote:
Is getComputedStyle something for you? Sample article:

http://www.csie.ntu.edu.tw/~b7506051...examples7.html




Reply With Quote
  #4  
Old   
DU
 
Posts: n/a

Default Re: how to retrieve DIV position??? - 02-05-2004 , 10:29 AM



Billy wrote:

Quote:
Hi, I was wondering how to retrieve the cordinates of a CSS layer with
javascript.

I set the layer cordinates as like this in the header:

style type="text/css"
.classID {
position: absolute;
left: 2px;
top: 100px;
}
/style

then in the body I have:

div id="layerID" class="classID"
some html and text
/div

The layer positions properly so I know that works.

and then in a javascript function I try to retrieve the cordinates by:

toppos = document.getElementById("layerID").style.top;
leftpos = document.getElementById("layerID").style.left;

but leftpos and toppos always come back blank.

It should not... unless layerID has moved, was dynamically moved: you do
not say that in your post description.

Quote:
Thanks in advance!
Billy


var toppos, leftpos;

toppos = parseInt(document.getElementById("layerID").style. top, 10);
leftpos = parseInt(document.getElementById("layerID").style. left, 10);

DU


Reply With Quote
  #5  
Old   
DU
 
Posts: n/a

Default Re: how to retrieve DIV position??? - 02-05-2004 , 10:33 AM



Bas Cost Budde wrote:

Quote:
Billy wrote:

Hi, I was wondering how to retrieve the cordinates of a CSS layer with
javascript.


Is getComputedStyle something for you? Sample article:

http://www.csie.ntu.edu.tw/~b7506051...examples7.html

But this will only work in DOM 2 Views and DOM 2 CSS compliant browsers.
MSIE 6 for windows does not support DOM 2 Views and has limited support
for DOM 2 CSS.

DU


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.