Skip to content

Instantly share code, notes, and snippets.

@masautt
Last active September 3, 2019 23:02
Show Gist options
  • Save masautt/c371f6ad001e3cd5111019ac897c1f0f to your computer and use it in GitHub Desktop.
Save masautt/c371f6ad001e3cd5111019ac897c1f0f to your computer and use it in GitHub Desktop.
How to prevent submit button from refreshing page when clicked using JavaScript
document.getElementById("myBtn").addEventListener("click", e => {
//some code
e.preventDefault(); //This specifically removes the default behavior of refreshing the page
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment