Reputation: 355
If I attach an event handler using .ajaxStop like this:
$(document).ajaxStop(function() {
//Some code
});
How do I remove that event handler?
Upvotes: 8
Views: 5553
Reputation: 185
If you need to ensure that the handler code inside ajaxStop() method is executed before it is removed, I propose the following:
$(document).ajaxStop(function(){
// Functions there
$(this).unbind("ajaxStop");
});
Particulary useful if you have various possible $.ajax in the same page and you want to control where to execute the ajaxStop() code. Then you just have to use this code inside the needed jQuery function.
Upvotes: 0
Reputation: 181
Try unbinding it, like so:
$(document).ajaxStop(function () {
$(this).unbind("ajaxStop");
//Some code
});
It's how I've been doing it.
Upvotes: 17