PDA

View Full Version : get coordinates of <div> tag



suman
11-20-2006, 05:29 AM
hi,
I had designed an html page, inside the <body> <div>table code</div> i had written the code for a table.I had added a border for the table using a .css file. now i want to get the height, width of the table dynamically.plz help me to write the code.its urgent for my project.

jscheuer1
11-20-2006, 07:22 AM
It depends upon the what will do and what is known. I recently wrote a script where this needed to be known and did it this way:


<div id="tablecontainer">table code</div>


var tableHeight=document.getElementById('tablecontainer').getElementsByTagName('table')[0].offsetHeight;
var tableWidth=document.getElementById('tablecontainer').getElementsByTagName('table')[0].offsetWidth;

If your table has an id, you can go straight for the table:


var tableHeight=document.getElementById('table_id').offsetHeight;

The bottom line is that an element's width is its offsetWidth and its height is its offsetHeight. If these things (width and height) are set using attributes or style, the element may often be queried for their values but, with tables and some other elements, the content influences the actual layout width and height sometimes more than the dimensions we set for them do.