From 3b81a6240be46ebfcba72508ab65634c953fdb85 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 22 Apr 2020 22:33:29 +0200 Subject: [PATCH] [TASK] refactor queryselector - ignore only #-hrefs --- .vscode/settings.json | 3 +++ script.js | 12 +++++------- 2 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..23473e4 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "gitea.repo": "ferienwohnung-wanderlust" +} \ No newline at end of file diff --git a/script.js b/script.js index e93784c..cfd48d0 100644 --- a/script.js +++ b/script.js @@ -20,14 +20,12 @@ document.addEventListener('DOMContentLoaded', function () { } } - var hashAnchors = document.querySelectorAll("a[href^='#']"); + var hashAnchors = document.querySelectorAll("a[href^='#']:not([href='#'])"); for (var i = 0; i < hashAnchors.length; i++) { - if (hashAnchors[i].getAttribute("href") != "#") { - hashAnchors[i].onclick = function () { - var target = this.getAttribute("href"); - scrollToElement(target); - return false; - } + hashAnchors[i].onclick = function () { + var target = this.getAttribute("href"); + scrollToElement(target); + return false; } }