Reputation: 823
I have a datatable
in my project which works perfectly, in the last column I'm adding a button for each row which also works fine.
I'm assigning a specific value to the id
attribute of this button and trying now to get that value when clicking on the button but I didn't manage to get that
Any suggestions please?
var table = $("#example").DataTable();
$('#example tbody').on('click', 'button', function () {
var id = table.row($(this).attr('id'));
console.log(id);
});
but the above code returns:
[0: Array[0], context: Array[1], selector: Object, ajax: Object]
Upvotes: 0
Views: 3639
Reputation: 275
If the 'id' attribute assigned to your button
use this;
var table = $("#example").DataTable();
$('#example tbody').on('click', 'button', function () {
var id = $(this).attr('id'); //$(this) refers the clicked button element
console.log(id);
});
Upvotes: 1