jquery - invoke javascript on button click of a datatable row -
im using datatable , have following:
var otable = $('#example').datatable({ bprocessing: true, sajaxsource: "/cart/addresses", 'idisplaylength': 5, aasorting: [], aocolumns: [ { "mdata": "contact" }, { "mdata": "address" }, { "mdata": "postcode" }, { "mdata": null, "mrender": function (data, type, full) { return '<button type="button" class="btn btn-success use-address" onclick="dofunction();" role="button" data-adcode="' + full.adcode + '">' + 'use address' + '</button>'; } } ] });
i have tried following, want bale use adcode when button clicked:
$('.use-address').click(function () { var adccode = $(this).data("adcode"); }); function dofunction() { var adccode = $(this).data("adcode"); }
this wont work, in firebug doesnt hit either of these.
note datatable added dynamically (after clicking button.)
any ideas why aint working?
thanks
try use event delegation here:
$('#example').on('click','.use-address',function () { var adccode = $(this).data("adcode"); });
Comments
Post a Comment