Kalinka Kalinka - 1 year ago 87
HTML Question

Will a jQuery function will still work on an AJAX call returned HTML table?

I have a form on my page that submits the form via AJAX and then there is a script that processes some MySQL data and returns the data formatted as a

and displays it. I wanted to added sorting capabilities to this table, and found this simple but yet usefull plugin.

The issue is that it is not working for me. I tried adding the code in the
portion of my JavaScript file, as well as outside of it. But there is still no effect. Is the onClick function is set when the page loads? and because the page is not refreshed when the table is shown - the onClick is not bound to it?

In that case, how can I bind jQuery to the returned table?

Answer Source

It is recommended to use the .on() method of JQuery.

Something like:

$('.selector_for_table').on('click', '.selector_of_header', function(e){ //logic })

Recommended reading: Jquery documentation .on()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download