Handling an Event Callback Once

An interesting tidbit I stumbled upon recently is the ability to remove an event listener once called.

In the past, I would have added an event listener to an element and then removed it within the callback function. It would have looked something like this:

const button = document.querySelector('button')

button.addEventListener('click', function onClick() {
  button.removeEventListener('click', onClick)

Welcome Readers

I’m a designer turned web developer that specializes in front-end applications. As an advocate for best practices and proper schematics, I believe that the web should be open and accessible for everyone.

  • 2 min read