Home > Article > Web Front-end > JS method to dynamically delete specified rows from a table_javascript skills
The example in this article describes the JS method of dynamically deleting specified rows from a table. Share it with everyone for your reference. The details are as follows:
The JS table object has a deleteRow method for deleting specified rows in the table. You only need to 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 will be helpful to everyone’s JavaScript programming design.