i have many events such as
$('.hidefile').click(function (event) {
On page load and on certain conditions i use ajax to get the html for a certain div and fill it in with .html(htmlstring). It took me forever but i notice that the events do not work when i do this. How do i fill the div with html and have the jquery events work with it?
Bind your click events (or otherwise) to your elements using live:
$('.hidefile').live("click", function (event) {...
When you replace elements using ajax, they lose their event handlers. You can either explicitly rebind them within the success callback of the particular ajax method you have used to replace those elements, or use live handlers instead, which will:
Attach a handler to the event for all elements which match the current selector, now or in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With