logo
post image

Creating One Time Executing Events in Javascript

If we need a Javascript event to execute only once, we can use the once option as parameter to the addEventListener() method.

By setting the once option to true, the event listener will be invoked only once. After that it will be automatically removed.

document.querySelector("#my-button").addEventListener('click', function() {
	// event handler
}, {once: true});