473,383 Members | 1,855 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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 1880
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Poonam | last post by:
Hi there. How can i maintain the spacing between to divs if palced side by side with 10px spacing between them.. Not using any tables. And atleast making one of the div relative positioning. ...
9
by: Preston Crawford | last post by:
I know this is probably a dumb question so please be patient with me. I've been doing HTML since 1994, but mostly for projects that had to be as completely compatible as possible and mostly...
16
by: Pierre Jelenc | last post by:
I need to lay out a page with five main elements: A fixed div at the top containing a navigation bar, two side-by-side columns, a centered shopping cart at the bottom, and a full-window fixed div...
0
by: Michael Ramey | last post by:
Hi, I've have two divs, that are laid out side-by-side. (I'm floating the first div to the left) I need to set up css on these two divs so that the second div is vertically aligned to the...
20
by: Tyler Carver | last post by:
I would like to do something that seems so basic with two div's but I don't think it can be done. Tables can do it in a snap. I was convinced that css was the way to go for layout but without...
15
by: red | last post by:
How do I center two side by side divs ? I've been writing css pages for a while but there's one thing tha still eludes me. I can center a div with margin auto. I can place two divs side by side...
6
by: =?Utf-8?B?Tkg=?= | last post by:
Hi, What do you recommend for defining the layout of an asp.net 2.0 page? Leaving masterpages and user controls aside for the moment is the use of tables or Divs the best approach? I have...
5
by: Test | last post by:
Is it possibel to have DIV's inside a table cell so that their position can be given relative to top left corner of the cell. Now the DIVs seem to position themselves relative to previous object.
3
jhardman
by: jhardman | last post by:
I'm almost to the point of using tables to position my elements. That is how bad this is. So here's the rundown. I have an old page (created by someone else) that I was trying to update to...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.