GezH
Programmer
- Aug 7, 2002
- 68
Hello. I create a javascript table as follows:
<body id="bodyNode"> // my body in html page
<table id="tableObj" /> // reference to the table in html page
// my javascript
var tableObj = document.createElement("table");
var tbodyObj = document.createElement("tbody");
// append lots of table data here...
// link the table to the html elements...
tableObj.appendChild(tbodyObj);
bodyNode.appendChild(tableObj);
This all works fine. But, I call my function several times. Each time a new table is appended to the bodyNode, with the existing table still there, rather than a new table being created from scratch. How do I ensure that the bodyNode object is cleared of the existing table before it creates a new one?
Many thanks for any help.
<body id="bodyNode"> // my body in html page
<table id="tableObj" /> // reference to the table in html page
// my javascript
var tableObj = document.createElement("table");
var tbodyObj = document.createElement("tbody");
// append lots of table data here...
// link the table to the html elements...
tableObj.appendChild(tbodyObj);
bodyNode.appendChild(tableObj);
This all works fine. But, I call my function several times. Each time a new table is appended to the bodyNode, with the existing table still there, rather than a new table being created from scratch. How do I ensure that the bodyNode object is cleared of the existing table before it creates a new one?
Many thanks for any help.