# Using addEventListener's \`{ once: true }\` option for single-shot events

**URL:** <https://forum.kirupa.com/t/using-addeventlisteners-once-true-option-for-single-shot-events/683855>\
**Category:** web dev\
**Created:** [October 29, 2026, 12:18am UTC](https://forum.kirupa.com/t/using-addeventlisteners-once-true-option-for-single-shot-events/683855 "2026-10-29T00:18:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yoshiii](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/yoshiii/32/31156_2.png) [@Yoshiii](https://forum.kirupa.com/u/Yoshiii)\
**Post date:** [October 29, 2026, 12:18am UTC](https://forum.kirupa.com/t/using-addeventlisteners-once-true-option-for-single-shot-events/683855/1 "2026-10-29T00:18:09Z")

</div>

Source: [HariSeldon, post #2](https://forum.kirupa.com/t/683700/2), [Yoshiii, post #3](https://forum.kirupa.com/t/683700/3)

It’s super cool that `addEventListener` lets us have multiple handlers for the same event, like Hariseldon mentioned in the quiz discussion ([JS Quiz: Easy: Simplest DOM event listener - #2 by HariSeldon](https://forum.kirupa.com/t/683700/2)). That’s a huge upgrade from the old `onclick` days! I was playing around with it and thought, what if we want to _temporarily_ listen for something? Or maybe just once? `removeEventListener` is great for cleanup, but `once` makes it even cleaner for single-shot actions. It’s so handy for things like intro animations or one-time user prompts.

Here’s a quick example where a button changes color only on its first click, then stops listening:

```html
<button id="myTemporaryButton">Click me once!</button>

```

```javascript
const myTemporaryButton = document.getElementById('myTemporaryButton');

const handleClickOnce = () => {
  myTemporaryButton.style.backgroundColor = 'lightcoral';
  myTemporaryButton.textContent = 'Clicked!';
  console.log('This handler ran only once!');
};

myTemporaryButton.addEventListener('click', handleClickOnce, { once: true });

// Try clicking multiple times, it only fires the first time.

```
