Created
May 22, 2011 23:28
-
-
Save vladocar/986000 to your computer and use it in GitHub Desktop.
Event Delegate 2
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 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