Nick
Nick

Reputation: 2641

Delete parent of button

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

Answers (1)

Roko C. Buljan
Roko C. Buljan

Reputation: 206593

You mean*:

<tr><th>Some text</th><th><button class="delete">Delete</button></th></tr>

DEMO

$('#table').on('click', '.delete', function(){
   $(this).closest('tr').remove();
});

Upvotes: 2

Related Questions