Results 1 to 2 of 2

Thread: get coordinates of <div> tag

  1. #1
    Join Date
    Oct 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default get coordinates of <div> tag

    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.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    HTML Code:
    <div id="tablecontainer">table code</div>
    Code:
    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:

    Code:
    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •