Skip to content

Instantly share code, notes, and snippets.

@planetoftheweb
Created February 8, 2023 02:27
Show Gist options
  • Save planetoftheweb/ea85601e7d437e8f4f37d44c1149d40b to your computer and use it in GitHub Desktop.
Save planetoftheweb/ea85601e7d437e8f4f37d44c1149d40b to your computer and use it in GitHub Desktop.
Example of the preventDefault method
<!DOCTYPE html>
<html lang="en" dir="ltr" data-theme="light">
<head>
<meta charset="utf-8">
<title>Prevent Defaults</title>
<link rel="stylesheet" href="https://unpkg.com/@picocss/pico@1.*/css/pico.min.css">
</head>
<body >
<main class="container">
<h1>JavaScript Events</h1>
<article id="links">
<a role="button" href="https://raybo.org">Blog</a>
<a role="button" href="https://youtube.com/@planetoftheweb">YouTube</a>
<a role="button" href="https://linkedin.com/in/planetoftheweb">LinkedIn</a>
</article>
</main>
<script type="text/javascript">
document.getElementById("links")
.addEventListener("click", function (e) {
e.preventDefault();
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment