Last active
August 21, 2017 15:45
-
-
Save alexsasharegan/5f58a3a15b3929e2e4db884c636bbccb to your computer and use it in GitHub Desktop.
Add an event handler that unbinds after firing once (no jQuery).
This file contains 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
function addEventListenerOnce(node, event, callback) { | |
function listenOnce() { | |
node.removeEventListener(event, fnOnce) | |
return callback.apply(null, arguments) | |
} | |
node.addEventListener(event, fnOnce) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment