en.javascript.info/2-ui/2-events/01-introduction-browser-events/03-which-handlers-run/solution.md
Brent Guffens 82a34d231f
Small typo
2018-03-05 10:18:48 +01:00

16 lines
579 B
Markdown

The answer: `1` and `2`.
The first handler triggers, because it's not removed by `removeEventListener`. To remove the handler we need to pass exactly the function that was assigned. And in the code a new function is passed, that looks the same, but is still another function.
To remove a function object, we need to store a reference to it, like this:
```js
function handler() {
alert(1);
}
button.addEventListener("click", handler);
button.removeEventListener("click", handler);
```
The handler `button.onclick` works independently and in addition to `addEventListener`.