removeEventListener removes an event listener added with addEventListener. However, there are a number of gotchas to watch out for in order to correctly remove an event listener.

Sometime, if you passed third options to addEventListener, but you forgot to pass the same option when calling removeEventListener, the event won't be removed successfully

[Javascript] Remove an Event Listener with removeEventListener

 

Simple helper:

export default function bind(
  target, {type, listener, options}
) {
    target.addEventListener(
        type,
        listener,
        options,
    );

    return function unbind() {
        target.removeEventListener(
            type,
            listener,
            options,
        );
    }
}

 

相关文章:

  • 2021-11-26
  • 2022-12-23
  • 2021-11-02
  • 2021-08-14
  • 2021-06-03
  • 2022-12-23
猜你喜欢
  • 2021-06-13
  • 2022-12-23
  • 2021-10-30
  • 2021-07-30
  • 2022-12-23
  • 2022-12-23
  • 2022-03-04
相关资源
相似解决方案