Michael
Michael

Reputation: 2972

Cancel event listeners from element

Is there a way to cancel/remove all event listeners from an element? I didn't set these listeners by myself so I don't have a StreamSubscription I could use. I need to get them somehow.

So some library did this:

querySelector('body').onMouseUp.listen(handler);

And I want to remove that (and all other) handlers again.

Upvotes: 2

Views: 164

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657871

You can add an onMouseUp event handler in a child element and call stopPropagation and/or stopImmediatePropagation on the event to prevent the event from propagating up.

Upvotes: 1

Related Questions