Javascript examples for DOM HTML Element:Table
The deleteRow() method removes the row by index from a table.
table.deleteRow(index);
Value | Description |
---|---|
index | Required in Firefox and Opera, optional in IE, Chrome and Safari. |
-1 removes the last row will be deleted.
No return value
The following code shows how to Delete the first row in a table:
<!DOCTYPE html> <html> <head> <style> table, td { border: 1px solid black; } </style>/*w w w . j ava 2 s . c o m*/ </head> <body> <table id="myTable"> <tr> <td>Row1 cell1</td> <td>Row1 cell2</td> </tr> <tr> <td>Row2 cell1</td> <td>Row2 cell2</td> </tr> <tr> <td>Row3 cell1</td> <td>Row3 cell2</td> </tr> </table> <br> <button onclick="myDeleteFunction()">Delete row</button> <script> function myDeleteFunction() { document.getElementById("myTable").deleteRow(0); } </script> </body> </html>