Skip to content

Instantly share code, notes, and snippets.

@mjlescano
Last active August 29, 2015 14:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjlescano/58f0daa3e3d19e1210d9 to your computer and use it in GitHub Desktop.
Save mjlescano/58f0daa3e3d19e1210d9 to your computer and use it in GitHub Desktop.
jQuery event.preventDefault() and event.stopPropagation() shortcut.
/**
jQuery.Event.stop extension
===========================
Simple shortcut to do:
$(document).on('click', 'a', function(e){
return e.stop()
})
Istead of:
$(document).on('click', 'a', function(e){
e.preventDefault()
e.stopPropagation()
return false
})
**/
if( window.jQuery ) {
jQuery.Event.prototype.stop = function(){
this.preventDefault()
this.stopPropagation()
return false
}
} else {
window.console && console.warn('jQuery missing.')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment