Coordinates of divs and tables without absolute positioning?

  • Thread starter Siegfried Heintze
  • Start date
S

Siegfried Heintze

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
 
P

pcx99

Siegfried said:
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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top