My table td width in CSS is 150px.
I am thinking of using JavaScript to change the particular td width to 2px.
How can it be done?
To adjust column width automatically, click AutoFit Contents. To adjust table width automatically, click AutoFit Window.
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. Just keep in mind, the usage of style attribute overrides any style set globally.
Something like this (for the first one:
document.getElementsByTagName('td')[0].style.width = '2px';
Or this for all:
var tds = document.getElementsByTagName('td');
for (var i = 0; i < tds.length; i++)
tds[i].style.width = '2px';
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