Skip to content

Commit

Permalink
Check if menu button exists before adding an event listener
Browse files Browse the repository at this point in the history
  • Loading branch information
salixor authored and nicokaiser committed May 28, 2024
1 parent ce6ccac commit ac8b10d
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions assets/js/menu.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
const el = document.getElementById("menu-toggle");
el.addEventListener("click", (event) => {
event.preventDefault();
const target = document.getElementById("menu");
if (target.classList.contains("hidden")) {
target.classList.remove("hidden");
el.ariaExpanded = true;
} else {
target.classList.add("hidden");
el.ariaExpanded = false;
}
});
if (el) {
el.addEventListener("click", (event) => {
event.preventDefault();
const target = document.getElementById("menu");
el.ariaExpanded = target.classList.contains("hidden");
target.classList.toggle("hidden");
});
}

0 comments on commit ac8b10d

Please sign in to comment.