diff --git a/homepage/static/assets/js/mindflow.js b/homepage/static/assets/js/mindflow.js index 37bbae9..9d33f8d 100644 --- a/homepage/static/assets/js/mindflow.js +++ b/homepage/static/assets/js/mindflow.js @@ -1,13 +1,12 @@ -const buttons = document.getElementsByTagName("button"); const articles = document.getElementsByTagName("article"); document.getElementById("filter").classList.remove("hidden"); -for (let i = 0; i < buttons.length; ++i) - if (buttons[i].name !== "") - buttons[i].addEventListener("click", e => { - for (let j = 0; j < articles.length; ++j) - if (articles[j].id.startsWith(e.target.name) || e.target.name === "all") - articles[j].classList.remove("hidden"); - else - articles[j].classList.add("hidden"); }); \ No newline at end of file +function filter(e) { + for (const a of articles) + a.classList.toggle("hidden", + !(e.target.name === "all" || a.id.startsWith(e.target.name))); +} + +for (const b of document.getElementsByTagName("button")) + b.addEventListener("click", filter); \ No newline at end of file