Delete the first row in a table:
document.getElementById("myTable").deleteRow(0);
Click the button to remove the first row in the table.
<!DOCTYPE html> <html> <head> <style> table, td { border: 1px solid black; } </style>/*from ww w.j a v a 2 s .c om*/ </head> <body> <table id="myTable"> <tr> <td>cell 1</td> <td>cell 2</td> </tr> <tr> <td>cell 3</td> <td>cell 4</td> </tr> </table> <br> <button onclick="myFunction()">Test</button> <script> function myFunction() { document.getElementById("myTable").deleteRow(0); } </script> </body> </html>
The deleteRow()
method removes the row at the specified index from a table.
Parameter Values
Value | Description |
---|---|
index | Required. the position of the row to delete (starts at 0). |