JS implements a method to dynamically delete a specified row from a table

  • 2020-05-24 05:08:30
  • OfStack

This example demonstrates how JS implements the method of dynamically deleting a specified row from a table. Share with you for your reference. The details are as follows:

The table object of JS has an deleteRow method to delete the specified row in the table, just specify the row number


<!DOCTYPE html>
<html>
<head>
<script>
function deleteRow(r)
{
var i=r.parentNode.parentNode.rowIndex;
document.getElementById('myTable').deleteRow(i);
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
 <td>Row 1</td>
 <td><input type="button" value="Delete" onclick="deleteRow(this)"></td>
</tr>
<tr>
 <td>Row 2</td>
 <td><input type="button" value="Delete" onclick="deleteRow(this)"></td>
</tr>
<tr>
 <td>Row 3</td>
 <td><input type="button" value="Delete" onclick="deleteRow(this)"></td>
</tr>
</table>
</body>
</html>

I hope this article has been helpful to your javascript programming.


Related articles: