With JavaScript DOM delete rows in a table?

To delete rows in a table in JavaScript, use the DOM deleteRow() method.


You can try to run the following code to learn how to delete rows in a table. The code deletes rows one at a time −

Live Demo

<!DOCTYPE html>
      function captionFunc(x) {
         document.getElementById(x).createCaption().innerHTML = "Demo Caption";
      <table style="border:2px solid black" id="newtable">
         <input type="button" onclick="captionFunc('newtable')" value="Display Table Caption">
         <input type="button" value="Delete Row" onclick="document.getElementById('newtable').deleteRow(0)">
Sharon Christine
Sharon Christine

An investment in knowledge pays the best interest