Home >Web Front-end >JS Tutorial >How to clear the table using javascript_javascript skills
The example in this article describes how to clear the table using javascript. Share it with everyone for your reference. The details are as follows:
1. Normal method
Loop through the rows of the table and delete them one by one.
This method is a common method and is feasible, but it is not efficient.
2. Another method
var artTable = document.getElementById("artical_table"); console.debug(artTable.getElementsByTagName("thead")[0]); var artBody=artTable.tBodies[0]; //clear table //artBody.innerHTML=''; //获取tbody,清除innerHTML来达到清除表格数据,会报错 artBody.parentNode.outerHTML = artBody.parentNode.outerHTML.replace(artBody.innerHTML, ""); //解决tbody的innerHTML只读问题,这种也会有问题,会导致后面动态插入的行没有
I hope this article will be helpful to everyone’s JavaScript programming design.