Skip to content

addListener

Mike Byrne edited this page Mar 14, 2023 · 1 revision

description

Introduced 3.1.0

Add event listeners to node lists instead of singular nodes. (applies addEventListener to a NodeList)

requires

  • nothing

parameters

  • nodes - required - DOM NodeList to attach event listeners to
  • type - required - event type to listen for
  • func - required - the function to attach
  • options - optional - event listener options

returns

  • nothing

example usage:

function handler() {};

listeners.add(document.querySelectorAll('button'), 'click', handler);

With options set:

function handler() {};

listeners.add(document.querySelectorAll('button'), 'click', handler, { passive: true, once: true });

Note Remember, if you want to remove event listeners, you need to specify the same function reference and same options when removing as when adding.