Reputation: 1779
I am trying to use this row highlight function and it works when the page is loaded but when I use the pagination the function doesn't seem to stay on. The row no longer will highlight.
$("#json-table tbody tr").on("click", function(event){
$(this).toggleClass('row_selected');
});
Upvotes: 1
Views: 86
Reputation: 15616
Try:
$("#json-table").on("click", "tbody tr", function(){
$(this).toggleClass('row_selected');
});
Because you reload the table, you have to bind the on()
handler to something that won't be replaced, so use either #json-table
if you only alter the children, or its parent if not.
Upvotes: 3
Reputation: 7315
You are not using correct syntax for on(), use like this:
$(document).on('click','#json-table tbody tr', function(event){
$(this).toggleClass('row_selected');
});
Upvotes: 1