admin管理员组

文章数量:1208153

I've created cells for a dynamic table in html page using "document.createElement('td')" method & now wish to set width of each individual cell with some different value. Tried "cell.width = width" but it didn't work.

how can I achieve it?

I've created cells for a dynamic table in html page using "document.createElement('td')" method & now wish to set width of each individual cell with some different value. Tried "cell.width = width" but it didn't work.

how can I achieve it?

Share Improve this question asked Jan 18, 2013 at 8:59 user1976456user1976456 611 gold badge1 silver badge4 bronze badges 4
  • 3 cell.style.width = width? Welcome to SO! – 11684 Commented Jan 18, 2013 at 9:01
  • you want to change the width of the cell from the other corresponding cells in the table. – SHANK Commented Jan 18, 2013 at 9:02
  • @SHANK: no... actaully I'm adding cells to table dyanamically using some function in javascript & wish to add some code to set individual cell width right after I add a cell. :) – user1976456 Commented Jan 18, 2013 at 9:12
  • @11684: many thnx...... it workd... – user1976456 Commented Jan 18, 2013 at 9:49
Add a comment  | 

2 Answers 2

Reset to default 12

Use style.width:

var cell = document.createElement('td');
parent.appendChild(cell);
cell.style.width = '200px';

Here is an example.

To post my comment as an answer:

Use cell.style.width = width;.

本文标签: