JavaScript get Object dimensions?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

JavaScript get Object dimensions?

Post by Chris Corbyn »

Hi,

I know it's possible to get the screen dimensions and available screen height/width etc with JavaScript but I have not seen anywhere how to get the dimensions of say, a table cell or a whole table.

Basically I'm trying to tackle the table height="100%" problem by getting the height of the cell my table lives inside and then dynamically changing the height of the table to stretch to fit the cell. make sense?

So if I had....

Code: Select all

<table>
    <tr>
        <td id="needThisHeight">
            <table height="a value from some function that gets cell height">Stuff in the table</table>
        </td>
    </tr>
</table>
.... I'd want the table that sits inside the cell with id="NeedThisHeight" to stretch to fit it vertically 100% assuming that the height of the cell will not be fixed.

Any clues? 8O

Cheers :D
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

document.getElementById('NeedThisHeight').offsetHeight

Just spotted it in another bit a code and tested it for my case. Seems to work just perfect.
Post Reply