From: Ardis Lu Date: Sun, 14 Aug 2022 06:01:13 +0000 (-0700) Subject: Do not preventDefault on non-anchor clicks X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=f02db2c22d63a67d9d55152fe2f2e8ce9ad66cb1;p=ardislu.dev Do not preventDefault on non-anchor clicks Otherwise form submit and button click will not behave as expected --- diff --git a/script.js b/script.js index 47b3c47..99b3bbf 100644 --- 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. */