Skip to content

Instantly share code, notes, and snippets.

@ten1seven
Last active December 30, 2015 09:59
Show Gist options
  • Save ten1seven/7813061 to your computer and use it in GitHub Desktop.
Save ten1seven/7813061 to your computer and use it in GitHub Desktop.
Cross-browser event bubbling.
var body = document.getElementsByTagName('body')[0];
var captureEvent = function(e) {
var target = e.target || e.srcElement;
if (target.nodeName === 'A') {
alert(target.getAttribute('data-track'));
}
return false;
};
if (!body.addEventListener) {
body.attachEvent('onclick', captureEvent);
} else {
body.addEventListener('click', captureEvent, false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment