I am using jQuery DataTables for a table that loads data from the server using Ajax.
I have added a checkbox column and I need to fire an event every time I check a checkbox.
How can I do this?
Since, I think, you are adding these elements dynamically in render
function, you can use event delegation for the click event of the checkbox.
Event delegation allows us to attach a single event listener, to a parent element, that will fire for all descendants matching a selector, whether those descendants exist now or are added in the future.
Ref: http://learn.jquery.com/events/event-delegation/
Code:
$(document).on('click', '.chkRow', function () {
alert($(this).attr('value'));
});
I found a code for this purpose that add a checkbox on the row and on the click alert an attribute value.
Demo: https://jsfiddle.net/IrvinDominin/aqa61xdf/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With