JavaScript method deleteRow()
This section illustrates you the use of JavaScript method deleteRow(). The deleteRow() method removes the row at the specified position from a table.
Its syntax is:
table_object.deleteRow(index) |
This index starts from 0 and is relative to the logical order of all the rows contained inside the table. If the index is -1 the last row of the table is deleted.
Here is the code:
<html> <script> function deleteRow() { document.getElementById('table').deleteRow(1); } </script> <body> <h3>Employee Information</h3> <table id="table" border="1"> <tr> <th>Name</b></th> <th><b>Address</b></th> <th><b>ContactNo</b></th> </tr> <tr> <td>Angelina</td> <td>New Delhi</td> <td>1111111111</td> </tr> <tr> <td>Martina</td> <td>Mumbai</td> <td>2222222222</td> </tr> </table> <br /> <input type="button" onclick="deleteRow()" value="Delete Row"> </body> </html> |
Output will be displayed as:
On clicking the button, the row at the index 1 will be deleted.
Now if you click the button again, the row comes at the index 1 will be deleted.