Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 684
user1976456 Avatar asked Jan 18 '13 08:01

user1976456


People also ask

What is document createElement in Javascript?

In an HTML document, the document.createElement() method creates the HTML element specified by tagName, or an HTMLUnknownElement if tagName isn't recognized.

How fix TD table width?

Using width attribute: The <td> tag has width attribute to control the width of a particular column. By assigning a numeric value to this attribute between 0 to 100 in terms of percentage(or you can use pixel format). We can restrict the column width up to that much percentage of the table's total width.


2 Answers

Use style.width:

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

Here is an example.

like image 96
Minko Gechev Avatar answered Oct 16 '22 10:10

Minko Gechev


To post my comment as an answer:

Use cell.style.width = width;.

like image 30
11684 Avatar answered Oct 16 '22 11:10

11684