I have the following pretty standard process:
- I initialise my page in
$(document).ready. This includes binding events to elements in a table. - The content of the table is then refreshed dynamically through an ajax call
I now need to rebind events to the table content. Is there a standard way of doing this? i.e. is there an equivalent of $(document).ready that fires after a partial page DOM update?
Thanks.
Have a look at event delegation using live. From the docs:
An example:
That will preserve the event(s) bound to the cells on the table even after it has been replaced. The live manual says:
Alternatively, you can wrap your bindings into a function, and have that execute as a callback to the method that updates your table data, for instance:
Or if the entire table gets replaced dynamically, which is more likely: