Reputation: 2641
I was wondering how you would go about deleting a row in a table (HTML table) on the click of a button. At the moment the table is dynamically created with javascript and jQuery but I want to have a button that deletes the buttons row when selected. At the moment is this sort of what each row looks like in the table:
<tr><th>Some text</th><th><button type="button">Delete</input></th></tr>
Since each row has the same setup, is there a way to delete the parent <tr>
of the button that was clicked without the use of id's?
Upvotes: 1
Views: 315
Reputation: 206593
You mean*:
<tr><th>Some text</th><th><button class="delete">Delete</button></th></tr>
$('#table').on('click', '.delete', function(){
$(this).closest('tr').remove();
});
Upvotes: 2