I have a variable being set in a plugin JS file, and in my own custom JS file, I’m calling the same event to piggypack on the developers work.
The issue is I need to access a variable set in the plugin javascript event. It’s currently being set as follows in the plugin JS:
$('#link').live('click', function() {
var test = 123456;
var another = 'string';
$('body').trigger({
'test' : test,
'another' : another
});
});
Now, in my own custom JS, I’m calling the same method on the #link to add my own code to execute.
$('#link').on('click', function(){
// I need to access the another variable set previously
});
What I don’t really get is when the jquery docs say that the trigger method is passing arguments to the event handler. What does that mean exactly? How would I access the variable set in a previous event?
Thanks in advance as always.
NORMALLY, you would pass extra parameters to an event, IF it has a custom event, you can access that:
after this HIT event, the value of #hitter would have “hi123456” appended to it. To access the “another” is simply param1.another, which returns “string”.