Reputation: 249
I want to delete the row where the triggered button is. Every row has a button that calls a div or form. After the event on that div or form by clicking back, row should be deleted.
$('#btn1, #btn2').click(function() {
$('#myDiv').show();
$('#myTable').hide();
});
$('#bck').click(function() {
$('#myDiv').hide();
$('#myTable').show();
alert('DELETE THE ROW OF THE LAST TRIGGERED BUTTON, IF THE USER CLICK Btn 1 THE ROW WITH BTN 1 WILL BE DELETED');
})
;
Upvotes: 4
Views: 81
Reputation: 34117
Demo http://jsfiddle.net/DmWNz/ or http://jsfiddle.net/Sr28Q/
What I did: (for your specific need)
id
of the button.rowid
-- .replace(/[^\d]/g, '')
.remove()
api : http://api.jquery.com/remove/please note In the HTML the id
of the 2 buttons were same, they are fixed as well.
Rest should fit the need. :)
code
var rowId;
$('#btn1, #btn2').click(function () {
$('#myDiv').show();
$('#myTable').hide();
rowId = $(this).prop('id');
});
$('#bck').click(function () {
$('#myDiv').hide();
$('#myTable').show();
$('#myRow' + rowId.replace(/[^\d]/g, '')).remove();
alert('-- ' + rowId);
});
Upvotes: 1
Reputation: 8828
Here's one approach using a static variable:
window.btnId = $(this).attr("id");
and the closest function
$("#"+window.btnId).closest("tr").remove();
Upvotes: 1