As a rule, if you need access to the event, you do this through the parameter specified in the callback function:
$button.live("click", function(ev) {
But instead (for reasons too complicated to enter here), I donβt want to use an anonymous callback function, but instead specify a function to call, for example:
$button.live("click", functionToCall(ev, $(this));
So, you will notice that I have included "ev" as a parameter to functionToCall (), but this obviously will not work, because I do not use the anonymous callback function. But I still need to access this click event (to check ev.target) in functionToCall () function. My question is: how do I access this event? It would be nice if I could do something like this:
$button.live("click", functionToCall($(this));
and
function functionToCall($item) { var target = $item.event("click").target;
Any ideas would be greatly appreciated. Thanks.
javascript jquery events parameters anonymous-function
Matt powell
source share