itsmikem itsmikem - 2 years ago 55
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download