最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - how to set cell width in javascript just after creating it with 'document.createElement()' method? - Stac

programmeradmin3浏览0评论

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论