0

I have used live() to create a click event, on the table row, but the data in the table was getting cached, and then after some googling, I discovered that on() is the correct way to add an event to the selector.

$('#landingContactTable tbody tr').on("click", function(e) {
.
.

Table is showing 25 records, but has more records that can be viewed by clicking the "next" at the bottom of the table. But when I go to next set of records, I cannot select on the table rows, the click event somehow seems not working on the second set or records.

When I was using live(), it was caching the data and I was able to select the rows on the second set of records, but then I need a way to remove the "click" event if the user clicks "rest"?

Please let me know how to achieve this? Thanks

Pramod
  • 2,828
  • 6
  • 31
  • 40
Harbir
  • 453
  • 1
  • 7
  • 24

1 Answers1

1

That is not the way of using event delegation,as:

Event delegation allows us to attach a single event listener, to a parent element, that will fire for all descendants matching a selector, whether those descendants exist now or are added in the future.

Thus, you should use:

$('#landingContactTable tbody').on("click", 'tr',function(e) {
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125