How can I calculate the height of a row (in pixels) in a table with JavaScript?
<table>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
</table>
var trTagHeight = tableHeight/totalRowInTable; console. log(trTagHeight); //Note: This is approx value of each row, excluding padding and cell padding value. This is probably the closest answer so far. The only thing is that it won't guarantee any particular row... just the average height of all of them.
Change column and row height To change the height, do one of the following: To make all rows in the table the same height, select Layout > Distribute Rows. To make all the columns in the table the same height, select Layout > Distribute Columns. Note: In Excel, select Home > Format, and then select Row Height.
From the Table menu, select “Table Properties.” Click on the Table tab, then the Options button. Uncheck “Automatically resize to fit contents.” Click “OK.” Now click on the “Row” tab in Table Properties. Make sure that “Specify Height” is checked and the size in the middle box is the height you want your rows to be.
To set the cell width and height, use the CSS style. The height and width attribute of the <td> cell isn't supported in HTML5. Use the CSS property width and height to set the width and height of the cell respectively.
function findHeights() {
var tbl = document.getElementById('your table').rows;
alert(tbl[0].offsetHeight); // row 1
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With