468,119 Members | 1,910 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Coordinates of divs and tables without absolute positioning?

I want to implement drag and drop for tables, divs, spans. The problem is
that I don't know how wide or long my tables, divs and spans are going to be
in advance so I cannot use absolute coordinates. (It always seemed odd to me
that there is no function called GetExtent that would return the bounding
rectangle of an object -- this would solve my problem).

There is a way, however, to fetch the coordinates of an object (such as a
table, or td, or span) and then change the positioning to absolute and then
change the coordinates according to the mouse movements.

How do I get the coordinates? I tried doing
alert(document.getElementById('x').style.left) but this only returned an
empty string.

I know it is possible because I posted this query once before (about a year
ago) and received a response but cannot remember where I saved it!

Thanks,
Siegfried
Jul 23 '05 #1
1 1707
Siegfried Heintze wrote:
I want to implement drag and drop for tables, divs, spans. The problem is
that I don't know how wide or long my tables, divs and spans are going to be
in advance so I cannot use absolute coordinates. (It always seemed odd to me
that there is no function called GetExtent that would return the bounding
rectangle of an object -- this would solve my problem).

There is a way, however, to fetch the coordinates of an object (such as a
table, or td, or span) and then change the positioning to absolute and then
change the coordinates according to the mouse movements.

How do I get the coordinates? I tried doing
alert(document.getElementById('x').style.left) but this only returned an
empty string.

I know it is possible because I posted this query once before (about a year
ago) and received a response but cannot remember where I saved it!

Thanks,
Siegfried

Use DHTML. In the table or div tag add onMouseOver and onMouseOut
events to set a variable indicating which element the mouse is over.

IE <table onMouseOver="activeElement=1" onMouseOut="activeElement=0">

If you need precise coordinates, you can give the html element a name
tag then...

nameid=document.getElementById("name");
y=nameid.style.top;
x=nameid.style.left;
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Poonam | last post: by
16 posts views Thread by Pierre Jelenc | last post: by
reply views Thread by Michael Ramey | last post: by
20 posts views Thread by Tyler Carver | last post: by
15 posts views Thread by red | last post: by
6 posts views Thread by =?Utf-8?B?Tkg=?= | last post: by
5 posts views Thread by Test | last post: by
jhardman
3 posts views Thread by jhardman | last post: by
13 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.