Context for jQuery plugin event handlers.

Archived from the Transloadit support forum. Originally posted on December 1, 2010; details may be outdated, see our docs for current behavior. Original thread

I have a onCancel and onError function I want to share between several .transloadit() handlers. However, inside the shared functions, I don’t have a context of what form has triggered the function.

A simplified example:

var onErrorHandler = function() { 
    // what form triggered the error? 
};
$('form').transloadit({ ..., onError: onErrorHandler });

I guess you could solve this problem by wrapping your callbacks in a closure that sets the context.

But let’s make this good, how would setting the ‘this’ context to the form element the callback is on for all callbacks? Would that work for you?

That would be perfect.