In the documentation for .on()
, the parameters are given as follows:
.on( events [, selector ] [, data ], handler )
With regards to the handler
parameter (i.e. the callback function):
handler
Type:
Function( Event eventObject [, Anything extraParameter ] [, ... ] )
A function to execute when the event is triggered. The value
false
is also allowed as a shorthand for a function that simply doesreturn false
.
When are any extraParameter
arguments passed to the callback function? There are a lot of aliases for .on()
but I haven't e across any that pass more than the eventObject
parameter.
In the documentation for .on()
, the parameters are given as follows:
.on( events [, selector ] [, data ], handler )
With regards to the handler
parameter (i.e. the callback function):
handler
Type:
Function( Event eventObject [, Anything extraParameter ] [, ... ] )
A function to execute when the event is triggered. The value
false
is also allowed as a shorthand for a function that simply doesreturn false
.
When are any extraParameter
arguments passed to the callback function? There are a lot of aliases for .on()
but I haven't e across any that pass more than the eventObject
parameter.
2 Answers
Reset to default 5There is an example in the documentation:
$( "div" ).on( "click", function( event, person ) {
alert( "Hello, " + person.name );
});
//You can trigger an event without user action
$( "div" ).trigger( "click", { name: "Jim" } );
When are any extraParameter arguments passed to the callback function?
Utilizing .trigger(eventType [,extraParameters])
var obj = $({})
obj.on("evt", function(e, a, b) {
console.log(e, a * b)
});
obj.trigger("evt", [Math.random(), 100])
<script src="https://ajax.googleapis./ajax/libs/jquery/1.11.1/jquery.min.js"></script>