Passing additional arguments to event callback functions

In this example, the callback function for the click event refers to the DIV the event is attached to. But, suppose I wanted to make the callback a reusable function for other plots. I would need to also pass a handle for the DIV into the callback. For instance, in JQuery, you can add additional data to be passed by including it in object form between the event type and callback:

$("#id").on('click', {a: "extra", b: "data"}, handler);

function handler(event)
{
    console.log(event.a);
}

An event system also support jQuery so something like:

Plotly.plot('graph', data, layout);

$('#graph').on('click', {a: "extra", b: "data"}, handler);

should work.

I made an example for future seekers.

https://jsfiddle.net/abalter/2tw1bnzn/

Hiya! Plotly now has improved and consolidated Plotly.js event documentation here:

Please feel free to suggest documentation improvements in a pull request:

https://github.com/plotly/documentation/tree/source-design-merge/_posts/plotly_js/events