Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1594 How can I detect the width of a table?

You are here: irt.org | FAQ | JavaScript | Table | Q1594 [ previous next ]

Include a row with one column that contains a blank image, then test the width of the image:

<body onLoad="alert(document.images['tstimg'].width)">

<table width="100%" id="one">
<tr><td colspan="3"><img name="tstimg" src="blank.gif" width="100%" height="1"></td></tr>
<tr><td>blah blah...</td><td>blah blah...</td><td>blah blah...</td></tr>
</table>

</body>

You should really use the onLoad event handler to detect the width of the table, as with the latest browsers, the table width can change whilst the page is loading, as the borwser accomodates for wider objects. But, if you must you can detect the width of the table using the following:

<table width="100%" id="one">
<tr><td colspan="3"><img name="tstimg" src="blank.gif" width="100%" height="1"></td></tr>
<tr><td>blah blah...</td><td>blah blah...</td><td>blah blah...</td></tr>
</table>

</body>

<script language="JavaScript"><!--
alert(document.images['tstimg'].width);
//--></script>

Feedback on 'Q1594 How can I detect the width of a table?'

©2018 Martin Webb