How to clear a table using javascript
This example describes how to clear a table by using javascript. Share it with you for your reference. The details are as follows:
1. General Method
Loop the table's rows and delete them one by one.
This method is a common method that is feasible but inefficient.
2. Another Method
?
| 1 2 3 4 5 6 7 8 |
Var artTable = document. getElementById ("artical_table "); Console. debug (artTable. getElementsByTagName ("thead") [0]); Var artBody = artTable. tBodies [0]; // Clear table // ArtBody. innerHTML = ''; // Get tbody and clear innerHTML to clear table data. An error is returned. ArtBody. parentNode. outerHTML = artBody. parentNode. outerHTML. replace (artBody. innerHTML ,""); // Solve the tbody's innerHTML read-only problem. This will also cause the dynamic inserted rows to not exist. |
I hope this article will help you design javascript programs.