Forum Moderators: open

Message Too Old, No Replies

Clear cells and rows in a table using dom

Better yet, clear all table contents

         

codebreaker

5:42 pm on Aug 4, 2004 (gmt 0)

10+ Year Member



...Not just clear the cells, but delete them from the table (keeping only the <table> and <tbody> elements).

I am creating the table dynamically, and links in the table will recreate it, with new data. Everything is working perfectly, except the new data is appended at the bottom, because I can't get rid of the current stuff!

How do I do this? Thanks!

codebreaker

6:28 pm on Aug 4, 2004 (gmt 0)

10+ Year Member



I solved the problem by using a static div, instead of a static table. I now clear the contents of the div, and build the table from scratch each time. This solution works fine.

john_k

6:30 pm on Aug 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's a snippet I use for a table with the id="tblMeasures". In my case, the first row has TH cells, so this deletes all but the first row.

var oTable=document.getElementById("tblMeasures");
while(oTable.rows.length>1)
oTable.deleteRow(oTable.rows.length-1);