Skip to content

Instantly share code, notes, and snippets.

@electerious
Last active January 24, 2017 09:04
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 electerious/53c4f8015621790a46d5 to your computer and use it in GitHub Desktop.
Save electerious/53c4f8015621790a46d5 to your computer and use it in GitHub Desktop.
Stop event propagation and prevent the default
const stopEvent = (e = {}) => {
if (typeof e.stopPropagation==='function') e.stopPropagation()
if (typeof e.preventDefault==='function') e.preventDefault()
}
@electerious
Copy link
Author

electerious commented Nov 3, 2015

Example:

document.querySelector('.btn').onclick = function(e) {
    stopEvent(e)
    myEvent(this)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment