]> git.ardis.lu - ardislu.dev/commitdiff
Do not preventDefault on non-anchor clicks
authorArdis Lu <ardisglu@gmail.com>
Sun, 14 Aug 2022 06:01:13 +0000 (23:01 -0700)
committerArdis Lu <ardisglu@gmail.com>
Sun, 14 Aug 2022 06:01:13 +0000 (23:01 -0700)
Otherwise form submit and button click will not behave as expected

script.js

index 47b3c47488bc965211ff58867f9495a1a0cece89..99b3bbf37bbd2fef97826d7c60509accb47cc485 100644 (file)
--- a/script.js
+++ b/script.js
@@ -201,12 +201,11 @@ function route(href) {
 /* Set event handlers for client-side routing. */
 globalThis.addEventListener('popstate', _ => showPage(location.pathname));
 document.addEventListener('click', e => {
-  e.preventDefault();
   const anchor = e.target.closest('a');
-  if (!anchor) {
-    return;
+  if (anchor) {
+    e.preventDefault();
+    route(anchor.href);
   }
-  route(anchor.href);
 });
 
 /* DevTools console help message. */
This page took 0.060039 seconds and 4 git commands to generate.