I've attached some live() listeners in order to automatically make ajax calls for every link with ajax in the url:
$("document").ready(function() {
$('a[href^="/ajax"]').live('click', call);
});
function call(e, context, link) {
e && e.preventDefault();
link = link || this;
if(typeof link == "string" || !$(link).hasClass("disabled")) {
newObj(SPZ.AjaxCall, link, context);
}
};
But sometimes I want to override this (so that I can specify a context in which to find callback functions), so I wrote a jQuery method to do this
$.fn.customAjax = function(context) {
return this.die().click(function(e){
call.call(this, e, context);
});
};
$(".save").customAjax(myObj);
The problem I have is that if the live handler is added to a collection of elements I can't just use die() on one of those elements; die() only works, it seems, if you apply it to all the elements live() was used on.
Can anyone suggest a workaround that will suppress the live() event? And, as an aside, what are people's opinions on suggesting the jQuery team change the behaviour of die() so that it can be used to remove live() handlers on individual elements; are there any reasons why this would be a bad idea?