Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

datatables jquery click event not working after pagination

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

like image 219
ajay p Avatar asked Jan 18 '16 15:01

ajay p


1 Answers

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.

like image 60
squaleLis Avatar answered Sep 19 '22 11:09

squaleLis