/* Doesn't Work: Supposed to close toggle menu after clicking the menu items */
navToggle.forEach(link => {
link.addEventListener("click", () => {
document.body.classList.remove("nav-open");
});
});
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi,
Can you post the JavaScript code snippet that you have written? I would like to know if there's any syntax/logic error in your code.
Sure. This is my JavaScript.
const navToggle = document.querySelector(".nav-toggle");
const navLinks = document.querySelectorAll(".nav__link");
/This works/
navToggle.addEventListener("click", () => {
document.body.classList.toggle("nav-open");
});
/* Doesn't Work: Supposed to close toggle menu after clicking the menu items */
navToggle.forEach(link => {
link.addEventListener("click", () => {
document.body.classList.remove("nav-open");
});
});