0
votes

I have jquery datatable with 4 pages. When I load the page the click event works fine. From the second page onwards click event doesn't work. I read the http://api.jquery.com/on/ link, but I am confused making it work.

<table id="datatable">
<thead><th></th><th></th></thead>
<tbody></tbody>
</table>
$('#datatable tbody tr').find('td:gt(0):lt(9)').on("click", "", function(e) {
     e.preventDefault();
     e.stopPropagation.
});

The table loads as ajax client side, when I paginate the table is refreshed with new data. How to attach the click event to the next set of rows

Here is the link to jsfiddle

1
$('#datatable' tbody tr) --- what's this? ps: you don't use delegation - your second parameter in the on() call is an empty stringzerkms
@zerkms $('#datatable' tbody tr) enables click for the rows in the tbody. the second parameter is empty because I didn't know what to include in that.user525146
no it doesn't do that. It's a string literal and 2 undefined tokens (separated by space). This code is syntactically incorrectzerkms
@zerkms Sorry, its a typo $('#datatable tbody tr') I changed the quote at the end of truser525146
@zerkms can you please help me with this, I updated the question and also given an example in jsfiddle.user525146

1 Answers

0
votes

I believe the right syntax should be:

$('#datatable tbody tr').on("click", "td:gt(0):lt(2)", function(e) {});