Skip to content

Instantly share code, notes, and snippets.

@felixzapata
Created February 12, 2014 16:14
Show Gist options
  • Save felixzapata/8958680 to your computer and use it in GitHub Desktop.
Save felixzapata/8958680 to your computer and use it in GitHub Desktop.
A One-Time Event Creation Function
// create a one-time event
function onetime(node, type, callback) {
// create event
node.addEventListener(type, function(e) {
// remove event
e.target.removeEventListener(e.type, arguments.callee);
// call handler
return callback(e);
});
}
// one-time event
onetime(document.getElementById("myelement"), "click", handler);
// handler function
function handler(e) {
alert("You'll only see this once!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment