/    Sign up×
Community /Pin to ProfileBookmark

Adding COL to a table using DOM

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

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@marek_walfordauthorMay 30.2003 — 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
Copy linkTweet thisAlerts:
@marek_walfordauthorJun 02.2003 — 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.
×

Success!

Help @marek_walford spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...