Last active
October 21, 2016 06:53
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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