I am loading content into a page with ajax that will have live click events attached to them. It seems like the first time I load this content everything works as expected. If I load this again, the events fire twice (when put breakpoints in the code). What am I doing wrong? Is there a way I can clear the dom of these elements before they get loaded again?
I guess you're calling .live()
on the same elements again and again.
use .die()
on those elements before calling .live()
.
I fixed it like this:
$('selector').die('click').live('click', function () {
// Do stuff here
});
just confirmed. Was using .live() and experimented with .unbind() first.
final:
$(".clickedClass").die("click").live("click", function () {
});
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