C PWL
C PWL

Reputation: 519

Using JavaScript to change table cells width

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?

Upvotes: 6

Views: 32474

Answers (1)

qwertymk
qwertymk

Reputation: 35256

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';

Upvotes: 6

Related Questions