Categories
JavaScript Answers

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

Spread the love

To delete all rows in an HTML table with JavaScript, we use the remove method.

For instance, we write

document.querySelectorAll("table tbody tr").forEach((e) => {
  e.remove();
});

to select all tr elements with querySelectorAll.

Then we call forEach with a callback to call remove to remove each tr element.

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 *