Hello everyone. What would be the best way to send a message to the click event to find out from where it was called?.
$("#mybutton").click(function(ev){
if (called from funcion One or Two){
//my code
}
});
funOne = function(){
$("#mybutton").click();
};
funTwo = function(){
$("#mybutton").click();
};
EDIT:
on a "trigger" I have a small solution, but depends on all implement the parameter "data"
EDIT (II):
My solution based on a '@Roatin Marth' Answer.
jQuery.fn.trigger = function(event, data) {
var type = event.type || event,
expando = "jQuery" + (+new Date);
event = typeof event === "object" ?
// jQuery.Event object
event[expando] ? event :
// Object literal
jQuery.extend(jQuery.Event(type), event) :
// Just the event type (string)
jQuery.Event(type);
if (!event.caller) {
var xcaller = "";
try {
xcaller = arguments.callee.caller;
} catch (ex) { };
event.caller = xcaller;
}
return this.each(function() {
jQuery.event.trigger(event, data, this);
});
};
jQuery.fn.click = function(fn) {
var returned = null;
if (fn) {
returned = this.bind('click', fn)
} else {
var event = jQuery.Event('click'), xcaller = "";
try {
xcaller = arguments.callee.caller;
} catch (ex) { };
event.caller = xcaller;
returned = this.trigger(event);
}
return returned;
};