itsmikem itsmikem - 1 year ago 26
Javascript Question

jquery .on() with multiple events AND passing arbitrary data

I know you can pass multiple events to

like so:


...and I know you can pass arbitrary data along with
, like so:


But is there syntax to define multiple events while also passing arbitrary data? I'm not seeing how to do that in the docs.


You can pass data as the second optional parameter:

     mousedown: mouseDownFunction,
     mouseup: mouseUpFunction
}, {myParam: 5});

Then inside of the event handlers you will be able to access this data as, where e is a parameter (instance of an event object) of the invoked event handler function.