javascript method for clearing the table table

  • 2020-06-12 08:30:35
  • OfStack

This article gives an example of how javascript cleans up table tables. Share to everybody for everybody reference. The details are as follows:

1. The usual method

Loop through table's rows, then delete one by one.
This is the usual approach. It works, but it's not efficient.

2. Another way

var artTable = document.getElementById("artical_table"); 
var artBody=artTable.tBodies[0];
//clear table
// To obtain tbody To remove innerHTML To clear the table data , complains 
artBody.parentNode.outerHTML = artBody.parentNode.outerHTML.replace(artBody.innerHTML, "");
// To solve tbody the innerHTML Read-only problem , This can also be problematic, causing rows that are inserted dynamically later to fail 

I hope this article has been helpful for your javascript programming.

Related articles: