JavaScript navbar opening

I’m trying to do javascript navbar but for some reason can’t get it to work. I inspected those elements on the browser, but when I click the open button elements don’t get those classes. Could somebody check out what is my problem?

Here’s my Javascript:

const body = document.querySelector("body");
const navbar = document.querySelector(".main-menu");
const openButton = document.querySelector(".open-button");
const closeButton = document.querySelector(".close-button");

openButton.onClick = () => {
    navbar.classList.add("show");
    openButton.classList.add("hide");
    body.classList.add("disabled");
};

closeButton.onClick = () => {
    body.classList.remove("disabled");
    navbar.classList.remove("show");
    openButton.classList.remove("hide");
};

95 thoughts on “JavaScript navbar opening”

Leave a Comment