From f02db2c22d63a67d9d55152fe2f2e8ce9ad66cb1 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sat, 13 Aug 2022 23:01:13 -0700 Subject: [PATCH] Do not preventDefault on non-anchor clicks Otherwise form submit and button click will not behave as expected --- script.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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. */ -- 2.47.3