Using JavaScript to change the width of table cells

My CSS td table width is 150 pixels.

I am thinking of using JavaScript to change the specific td width to 2px.

How can I do that?

+5
source share
1 answer

Something like this (for the first:

document.getElementsByTagName('td')[0].style.width = '2px';

Or is it for everyone:

var tds = document.getElementsByTagName('td');

for (var i = 0; i < tds.length; i++)
    tds[i].style.width = '2px';
+6
source

All Articles