I have html table which i populate with content via ajax and php. I dinamiclly generate table rows and last column is row need to contain link/button where i need to call action for deliting that item (eg.Product) from table row.
I dont have idea how to call that specific ID becouse all is happening in loop each. Only in loop i have information about product id but in loop to call click() event not work and is so dumb for me. I think there is better solution to do that.
Check my code:
$.ajax({
url: '/admin/dokument/5/edit?ajax',
type: 'GET',
success: function(response) {
response = $.parseJSON(response);
$.each(response, function(i, item) {
i++;
var $tr = $('<tr>').append(
$('<td>').text(i),
$('<td>').text(item.id),
$('<td>').text(item.name),
$('<td>').text(item.qty),
$('<td>').text(item.jm),
$('<td>').text(item.price),
$('<td>').text(item.discount),
$('<td>').text(item.pdv),
$('<td>').text(item.total),
<!-- this is for delete -->
$('<td class="text-center">').html('<button type="button" id="product_'+item.id+'" class="btn btn-sm"><i class="fa fa-remove"></i></button>'),
// This not work inside loop
$("#product_"+item.id).click(function(e) {
alert(item.id);
}),
).appendTo('#document_items_table > tbody');
});
},
complete: function(){
$loading.hide();
}
Do you have any idea how to execute this for specific product? Thanks!