Skip to content

Instantly share code, notes, and snippets.

@vladocar
Created May 22, 2011 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladocar/986000 to your computer and use it in GitHub Desktop.
Save vladocar/986000 to your computer and use it in GitHub Desktop.
Event Delegate 2
function delegate(selectorParent, selectorChild, type, fn) {
var i = selectorParent.length;
while (i--) {
selectorParent[i].addEventListener(type, function (e) {
if ((selectorChild.indexOf(e.target)) >= 0) {
console.log("This", e.type, " was clicked!");
(function () {
fn();
})();
}
}, false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment