Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q1594 How can I detect the width of a table?

irt.org | Knowledge Base | JavaScript | Table | Q1594 [ previous next ]

Q1594 How can I detect the width of a table?

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?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.