Sign in to follow this  

[web] How do I create a table object using DOM?

This topic is 4257 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Aside from creating a table in HTML and then using document.getElementById() to get a table object, is there a way I can create a table object that is empty? For example, is there a Constructor where I can do this: MyTable= new Table();

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
var tbl = document.createElement('table');

Search for appendChild() to see how you can build up your table (with TR's and TD's), and then attach the table to your page.

Note, I'm pretty sure you'll find you can't your rows directly to your table object (in some browsers--I think it's a bug). Instead you have to add them to a TBODY element, which you can then add to the table.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Note, I'm pretty sure you'll find you can't your rows directly to your table object (in some browsers--I think it's a bug). Instead you have to add them to a TBODY element, which you can then add to the table.


If memory serves, that's actually following the standard. THEAD, TBODY, and TFOOT are supposed to be what TRs go under, not the table itself.

Share this post


Link to post
Share on other sites
Once you have created a table, you can use table DOM functions such as insertCell() and insertRow(). I used these functions in a demo but it doesn't seem to be much easier or faster than appendChild(). See http://members.optusnet.com.au/khsoh/0005.html and look at the javascript code if you are interested.

--

Share this post


Link to post
Share on other sites

This topic is 4257 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this