const addMultipleListeners = (el, types, listener, options, useCapture) => {
        types.forEach(type =>
          el.addEventListener(type, listener, options, useCapture)
        )
      }
      
      #Example
      addMultipleListeners(
        document.querySelector('.my-element'),
        ['click', 'mousedown'],
        () => { console.log('hello!') }
      )

      Javascript language logo
      Add multiple event listeners

      addMultipleListeners
      event
      listener
      Javascript recipes

      Adds multiple event listeners with the same handler to an element.

      Use Array.prototype.forEach() and EventTarget.addEventListener() to add multiple event listeners with an assigned callback function to an element.

      Shortcut: addMultipleListeners

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.