0

First the error which i am recievieng is undefined is not a function. I am generating a table on ajax call by button click. The problem is that the click event on cell is not performing.

my code is like

$(document).ready(function () {

   $('#btnCall').click(function () {
       $.ajax({....
          success: function (data) {
             //Here i am creating a table with id = myTable
          }
       });
   });

   //After ajax call completed i am using this 
   //but this is not happening
   //i want to show alert when cell clicked of the table
    $("#myTable tr td").click(function(event) {
         alert(event.pageX);
         alert(event.pageY);
    });
});
Hassaan
  • 3,931
  • 11
  • 34
  • 67

1 Answers1

0

You need to use jquery on event .

$("#myTable tr td").on('click', function(event) {
     alert(event.pageX);
     alert(event.pageY);
});
ashfaq.p
  • 5,379
  • 21
  • 35
  • 1
    `live()` was deprecated a **long** time ago. – Rory McCrossan Nov 11 '14 at 09:54
  • It is deprecated since version 1.7 and removed from version 1.9. – Barry Nov 11 '14 at 09:57
  • Your edit still won't work either. Firstly, `click` should be in quotes as it's a string, secondly the `#myTable` element doesn't exist on load, so the event can't be attached. You need to use the delegated event handler, as in the question I linked to. – Rory McCrossan Nov 11 '14 at 09:58
  • #myTable element does not exist at the time of load that is why we are using 'on' event handler instead of click , so it will work. – ashfaq.p Nov 11 '14 at 10:01
  • on is also not working going to check the delegate method – Hassaan Nov 11 '14 at 10:17