Skip to content

Instantly share code, notes, and snippets.

@dominikbulaj
Last active October 21, 2016 06:53
Show Gist options
  • Save dominikbulaj/d1d64d0dbe8c70138ed9711676b8e240 to your computer and use it in GitHub Desktop.
Save dominikbulaj/d1d64d0dbe8c70138ed9711676b8e240 to your computer and use it in GitHub Desktop.
one-time handling of the click event using vanilla addEventListener() From https://medium.com/dev-channel/once-upon-an-event-listener-f516bca519e6#.e9lx7f787
element.addEventListener('click', function cb(event) {
// ...one-time handling of the click event...
event.target.removeEventListener(event.type, cb);
});
// or:
element.addEventListener('click', function(event) {
// ...one-time handling of the click event...
}, {once: true});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment