Jump to content
  • Advertisement
Sign in to follow this  
ManaStone

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

This topic is 4619 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!