Page 1 of 1

JavaScript get Object dimensions?

Posted: Fri Sep 03, 2004 7:24 pm
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

Posted: Fri Sep 03, 2004 7:45 pm
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.