Sometimes, we want to delete all rows in an HTML table with JavaScript.
In this article, we’ll look at how to delete all rows in an HTML table with JavaScript.
How to delete all rows in an HTML table with JavaScript?
To delete all rows in an HTML table with JavaScript, we set the table’s innerHTML
property to an empty string.
For instance, we write
const table = document.getElementById("mytable");
table.innerHTML = "";
to select the table with getElementById
.
Then we set its innerHTML
property to an empty string to empty the table.
Conclusion
To delete all rows in an HTML table with JavaScript, we set the table’s innerHTML
property to an empty string.