Skip to content
Advertisement

on click event not working after append tbody in ajax call?

I am using php and mysql with jquery to display my data. The initial time my on click event is working on tbody.

But when I append tbody with ajax call it’s not working. I am using event delegation with .on

My html table : I am using simple html table to display my data and onclick of any TD adding ajax to append data.

JavaScript

my ajax call :

JavaScript

Advertisement

Answer

Try changing the selector to target the document like so:

JavaScript

This code $('#NewsTable tbody').empty(); is removing the elements which have listeners attached, and the new ones therefor do not have the click listeners after being appended.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement