Categories
JavaScript Answers

How to delete all rows in an HTML table with JavaScript?

Spread the love

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 can 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 remove all the rows.

Conclusion

To delete all rows in an HTML table with JavaScript, we can set the table’s `innerHTML property to an empty string.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *