Jump to content

Example Error - DOM Table Delete Row


Guest fabkins

Recommended Posts

Guest fabkins

There is an error with the JS DOM Delete Row example. The call makes the assumption that the "deleterow" property is available to a button which is not the case. This causes the example to always delete the first row instead of the row for which the button was pressed.The following is a working version of the example where i get the parent of the button (which is the cell) and then the parent of the cell to get the row. From there it can get the correct rowIndex.

<html><head><script type="text/javascript">function deleteRow(r)  {  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 am new to w3schools and this forum, I appologies if I posted this in the wrong place.

Link to comment
Share on other sites

Thank you for reporting the error and welcome to the forums. The moderator team is not directly related to the owners (and therefore maintenance) of the site. We will pass this along but we are unable to give you any indication when the error will be remedied.Thanks again and we look forward to your contributions.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...