Created
January 22, 2014 17:26
-
-
Save v0lkan/8563060 to your computer and use it in GitHub Desktop.
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
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget.addEventListener | |
function isSelfOrParentLink(node) { | |
while(node) { | |
if(node.nodeType.toLowerCase() === 'a') { | |
return true; | |
} | |
node = node.parentNode; | |
} | |
return false; | |
} | |
document.addEventListener("click", function(evt) { | |
var target = evt.target ? evt.target : evt.srcElement; | |
if (isSelfOrParentLink(target)) { | |
evt.preventDefault(); | |
doMagic(); | |
} | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment