6

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?

1 Answer 1

6

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';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.