javascript - Jquery datatables don't work on the second page -


i using jquery datatables plugin , not work after first page, event click function work on first page.

so have found out https://datatables.net/faqs/

q. events don't work on second page

a. when attaching events cells in table controlled datatables, need careful how done. because datatables removes nodes dom, events applied static event listener might not able bind nodes in table. overcome this, use jquery delegated event listener options, shown in example. additionally, use visual event bookmarklet debug event issues.

and suggest this:

$('#example tbody').on('click', 'tr', function () {     var name = $('td', this).eq(0).text();     alert( 'you clicked on '+name+'\'s row' ); }); 

it works, however, in case need selector this:

  $('#datatables tbody tr').on('click', 'td', function (event) {         if ($(this).attr('id') != "first" && $(this).parent().attr('data-href') !== undefined) {             document.location = $(this).parent().attr('data-href');         }     }); 

how fix problem keeping selector target? thanks.

you still need bind tbody "#example tbody", in second selector put "tr td", should still bind td after changing pages.

it's table rows , children change, binding statically them still missing point, have use optional binding parameter dive in changing elements, giving access them after change