Answers for "js change hamburger & show menu"

0

js change hamburger & show menu

var menu = document.querySelector(".header__main-nav")
var ham = document.querySelector(".header__burger-container")

ham.addEventListener("click", toggleMenu)

function toggleMenu() {
  if (menu.classList.contains("header__main-nav--show")) {
    menu.classList.remove("header__main-nav--show");
    ham.classList.toggle("change");
  } else {
    menu.classList.add("header__main-nav--show");
    ham.classList.toggle("change")
  }
}

var menuLinks = document.querySelectorAll(".header__main-link")

menuLinks.forEach(
  function (menuLink) {
    menuLink.addEventListener("click", toggleMenu)
  }
)
Posted by: Guest on September-09-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language