0

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

user525146
  • 3,918
  • 14
  • 60
  • 103
  • `$('#datatable' tbody tr)` --- what's this? ps: you don't use delegation - your second parameter in the `on()` call is an empty string – zerkms Feb 17 '13 at 20:50
  • @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 Feb 18 '13 at 08:34
  • no it doesn't do that. It's a string literal and 2 undefined tokens (separated by space). This code is syntactically incorrect – zerkms Feb 18 '13 at 09:17
  • @zerkms Sorry, its a typo `$('#datatable tbody tr')` I changed the quote at the end of `tr` – user525146 Feb 18 '13 at 09:28
  • @zerkms can you please help me with this, I updated the question and also given an example in jsfiddle. – user525146 Feb 19 '13 at 20:40

1 Answers1

0

I believe the right syntax should be:

$('#datatable tbody tr').on("click", "td:gt(0):lt(2)", function(e) {});
flavianatill
  • 484
  • 3
  • 9
  • Interestingly this doesn't work with jQuery 1.7 (only the first row functions) but does with jQuery 1.8 onwards. See [this jsFiddle](http://jsfiddle.net/vogomatix/bNvhH/52/) – vogomatix Jun 18 '14 at 11:35