I am using http://datatables.net/
<button class='btn btn-success activeAccount'>Activate Account</button>
I trigger ajax call on onclick event, below is ajax call code:
$(".activeAccount").click(function() { var intCounselorId = $(this).parent().parent().find('input[class="counselorId"]').attr("value"); var intOwnerId = $(this).parent().parent().find('input[class="userID"]').attr("value"); var strAction = 'activateAccount'; performAction(intCounselorId, intOwnerId, strAction); }); function performAction(intCounselorId, intOwnerId, strAction) { $.ajax({ url: '/admin/counselormanagement/expertmanagementgridaction', data: 'intCounselorId='+intCounselorId+'&intOwnerId='+intOwnerId+'&strAction='+strAction, type: "POST", async:false, success: function(intFlag) { if(intFlag == 1){ location.reload(); } } }); }
I'm trying to run an onclick event which works normally on page one, but as soon as I go to page 2 (or any other) it stops working.
I'm using jquery-1.10.2.min.js and 1.9.4 version of datatable
Because the event is attached only to existing elements.
You should change it to:
$("#tableId").on("click", ".activeAccount", function(){ // your code goes here });
Read more in the documentation of jQuery.on.
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