document.querySelector() methods to get a reference to the table element. Once you have a reference to the table, you can use the
deleteRow() method to remove the row from the table.
Here’s an example of how to delete a row from a table with an ID of
// Get a reference to the table var table = document.getElementById("my-table"); // Get a reference to the row you want to delete var row = table.rows[rowIndex]; // Delete the row table.deleteRow(rowIndex);
In this example,
rowIndex is the index of the row you want to delete (starting at 0 for the first row). The
rows property of the table element is an array-like object that contains all the rows in the table. You can access a specific row using its index.
Note that when you delete a row from a table, all the cells in that row will also be removed. If you need to delete only a specific cell, you can use the
deleteCell() method instead.