How to delete row from table using javascript?

PURU

I was trying on button click delete the row from table in javascript.I am able to do so usig jquery, but is it possible to do using pure vanilla javascript.

Is there way to use click event and delete the row ?

$(".delete").click(function() {
  $(this).closest("tr").remove();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
  <tr>
    <td>Row 1</td>
    <td><button class="delete">Del</button></td>
  </tr>
  <tr>
    <td>Row 2</td>
    <td><button class="delete">Del</button></td>
  </tr>
  <tr>
    <td>Row 3</td>
    <td><button class="delete">Del</button></td>
  </tr>
</table>

Ali Faris

I added onClick for each button

function deleteRow(button) {
     const tr = button.parentNode.parentNode;
     tr.parentNode.removeChild(tr);
}
<table id="table">
  <tr>
    <td>Row 1</td>
    <td><button onClick="deleteRow(this);" class="delete">Del</button></td>
  </tr>
  <tr>
    <td>Row 2</td>
    <td><button onClick="deleteRow(this);" class="delete">Del</button></td>
  </tr>
  <tr>
    <td>Row 3</td>
    <td><button onClick="deleteRow(this);" class="delete">Del</button></td>
  </tr>
</table>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to delete row from table column javafx

How to delete a row from a table

How to delete a specific row in a table using javascript?

Try to delete entire row from table using delete button in PHP

How to delete a row from a table in SQL Server using PowerShell script?

Delete A Record From Dynamic table using javascript

How to delete a row in the table when I click on a button? Using Javascript

how to delete a row from table using Angular5?

How to delete a table row which is using nested loop using angular

How to remove the row in a table when clicked on "delete icon" using javascript/jquery?

How to delete each third row from <tbody> using only JavaScript?

Delete an entire row from a table, using MySQL

unable to delete row from table using jquery?

How to get the label value from table row when row number is known, using Javascript

How to delete row from table without delete a row from referenced table?

why can't i delete a row in table from javascript?

How to delete table certain table row created from dynamic dataTables using jquery?

To delete a row dynamically from a table using javascript

Delete row of the table using javascript

How to update the table row on delete row in another table using Doctrine?

Delete row from table using Vue

How to delete a single row from the table fast?

How to delete the duplicates from the table using row_number() in psql?

How to delete post from table row using ajax for asp.net mvc?

How to delete last row from table in xslt

Delete a row from a table using and Id React

how to delete a row from the table with a button on react?

How to delete a row from a HTML table with React?

i want to delete a row from table in javascript which stored in localstorage