Alvin Alvin - 1 year ago 71
HTML Question

Click a button on the row of the table and remove the row using javascript

<table id="myList">
<th>Product ID</th>
<th>Product Name</th>

I currently have a row in the table. I have a button on the very last column of the row. How do I remove/delete the row when i click the button and invoke a function?

Answer Source

You can use rowIndex to find which row need to be deleted.

Use deleteRow method to delete the row

Hope this snippet will be useful.

Here x will be the button

x.parentElement will be the td which contain the button

x.parentElement.parentElement will be the tr which need to be deleted

function delRow(x){


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download