Using % on a table width, is it possible to get the width in pixel size?

R

RMZ

If you have an HTML table defined like so

<table border="1" width="100%" height="100%">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>

Is it possible using JavaScript to return the width and height pixel
counts for the width and height of the table?
 
J

jamie.ly

If you have an HTML table defined like so

<table border="1" width="100%" height="100%">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>

Is it possible using JavaScript to return the width and height pixel
counts for the width and height of the table?

If you are willing to use prototype.js (Prototype library
http://prototypejs.org/api), you can simply call

$('tableid').getDimensions(); and it will return an object { width: 0,
height: 0 };
 
D

David Mark

If you are willing to use prototype.js (Prototype libraryhttp://prototypejs.org/api), you can simply call

$('tableid').getDimensions(); and it will return an object { width: 0,
height: 0 };

Assuming the table does not have a display style of "none", you can
use the offsetWidth and offsetHeight properties of the table element.
That is what Prototype sends back for displayed elements. This will
save you 70K of extra page weight.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top