question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unbind click event

See original GitHub issue

Hi, I have a single page application which contains a plotly chart with click event handler in it. I have another function which removes the chart and plot a new chart after certain events.

Plotly.newPlot(plotSpace, data, layout)
plotSpace.on('plotly_click', click => {
  listAllTransactions(town, click.points[0].data.name, click.points[0].x)
})

Each time the plot is replaced with a new one, the event handler from the previous chart is carried over to the new chart, so a click on the new chart will trigger listAllTransactions twice: first with town from the first chart and second with town from the second chart.

How can I remove the event handler from the first chart? I’ve tried removeEventHandler to no avail.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
chriddypcommented, Feb 14, 2017

Is there any other way to remove or rebind existing handlers without calling newPlot? This issue was the first hit in a google search. Also this stack overflow question is linking here: http://stackoverflow.com/questions/37372193/unbind-click-events-in-plotly

0reactions
alexcjohnsoncommented, Feb 14, 2017

I don’t see that we document or test this anywhere, but we do support removeListener and removeAllListeners from the npm events module:

function logIt(e) { console.log(e) }

gd.on('plotly_relayout', logIt)

Plotly.relayout(gd, {'xaxis.range': [-1,5]})
// here the listener is invoked
> Object {xaxis.range: Array[2]}
> Promise {[[PromiseStatus]]: "resolved", [[PromiseValue]]: div#graph.dashboard-plot.js-plotly-plot}

gd.removeListener('plotly_relayout', logIt)

Plotly.relayout(gd, {'xaxis.range': [-2,6]})
// now the listener is not invoked
> Promise {[[PromiseStatus]]: "resolved", [[PromiseValue]]: div#graph.dashboard-plot.js-plotly-plot}
Read more comments on GitHub >

github_iconTop Results From Across the Web

.unbind() | jQuery API Documentation
A string containing one or more DOM event types, such as "click" or "submit," or custom event names. ... The function that is...
Read more >
jQuery unbind() Method - W3Schools
The unbind() method removes event handlers from selected elements. This method can remove all or selected event handlers, or stop specified functions from ......
Read more >
Best way to remove an event handler in jQuery?
This can be done by using the unbind function. $('#myimage'). unbind('click'); You can add multiple event handlers to the same object and event...
Read more >
How to Remove an Event Handler using jQuery
Select the selector on which the event handler is to be removed. · Use the unbind() method to remove event. · After click...
Read more >
Working of jQuery unbind() Function | Examples - eduCBA
The jQuery unbind() function is a built in function in jQuery. The unbind() function remove event handler which was added by using the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found