Reputation: 455
How can I get a tables first td element's width and height?
<div class="page">
<table>
<tr>
<td></td>
...
</tr>
</div>
Upvotes: 0
Views: 1473
Reputation: 15509
You can use clientHeight and clientWidth - note that the queryAll selector is only targetting the single td in this demo - you will need to extend that selector to get the correct TD that you are after.
let tableCell = document.querySelector('td');
let cellWidth = tableCell.clientWidth +'px';
let cellHeight = tableCell.clientHeight +'px';
console.log('width: ' + cellWidth, ' / height: ' + cellHeight);
<div class="page">
<table>
<tr>
<td>Test</td>
</tr>
</table>
</div>
Upvotes: 3