const listenOnce = (el, evt, fn) => el.addEventListener(evt, fn, { once: true })
#Example
listenOnce(
document.getElementById('elementId'),
'click',
() => console.log('Hello world')
); // 'Hello world' will only be logged on the first click
Listen for an event only once
The code above will create a listener that will only be called once.
Shortcut: singleEventListener
0 Comments
Add Comment
Log in to add a comment