Click to See Complete Forum and Search --> : Adding COL to a table using DOM


marek_walford
05-30-2003, 06:39 AM
Hi,

Has anybody successfully added a COL to an HTML table using the DOM and appendChild? I am currently setting the width of a column by setting the width of each cell. I want to set the width on just the column. Although the code doesn't error it doesn't have any effect. However, if I debug and get the innerHTML and paste it into a new HTML document the effect of my width change is apparent.

The snippet of code I'm using is:

var oCol = document.createElement("COL");
oCol.width = 100;
oTableBody1.appendChild(oCol);

Any ideas?

Many thanks,
Marek Walford

marek_walford
05-30-2003, 08:27 AM
I've tried:

oCol.style.width = 100;
oCol.style.width = "100px";
oCol.setAttribute("width", 100);
oCol.width = 100;

It's something to do with the DOM becuase I can get the innerHTML and documnet.write it and it's fine!

Marek

marek_walford
06-02-2003, 04:23 AM
I've found the source of the problem. You cannot have a COL element without a COLGROUP element. As soon as I added the COLGROUP everything worked fine.