Skip to content

Instantly share code, notes, and snippets.

@learning
Created June 15, 2012 03:30
Show Gist options
  • Save learning/2934517 to your computer and use it in GitHub Desktop.
Save learning/2934517 to your computer and use it in GitHub Desktop.
Cancel bubble
elem.onclick = function(e){
e = e || window.event; // IE's event is window.event
var target = e.target || e.srcElement; // IE's target is srcElement
if(target.nodeName !== 'A'){
return;
}
if(typeof e.preventDefault === 'function'){
e.preventDefault();
e.stopPropagation();
}else{ // IE
e.returnValue = false;
e.cancelBubble = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment