Last active
August 29, 2015 14:07
-
-
Save mjlescano/58f0daa3e3d19e1210d9 to your computer and use it in GitHub Desktop.
jQuery event.preventDefault() and event.stopPropagation() shortcut.
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
/** | |
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