Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

199
Visualizações
Java script / html / nav Hamburger is not working properly with ID's - menu doesn't close

I'm working on my very first webpages. The navigation bar consists of 5 sections/links (3 pages) - 1st page contains 3 links with ID's within one page + the are two linked simple pages. With two simple pages the hamburger menu works without any problem - it opens after clicking at hamburger, when I click on any section, the navigator closes automatically. The problem is when I click on the menu in the page, where the three ID's are. The navigation bar opens, the webside moves into the point where the ID is, however the navigation bar doesn't close. Please see below attached the code. Could you please help? thank you

let menu = document.querySelector(".menu")
let menuIcon = document.querySelector(".menu-icon")
menuIcon.addEventListener("click", function() {
  let iconSrc = menuIcon.src
  console.log(iconSrc);
  let splitIconSrc = iconSrc.split("/")
  console.log(splitIconSrc);

  let imgName = splitIconSrc[splitIconSrc.length - 1]

  if (imgName == "hamburger.png") {
    menuIcon.src = "img/krizek.png"
    menu.style.left = "0px"
  } else {
    menuIcon.src = "img/hamburger.png"
    menu.style.left = "-120%"
  }
})
<nav>
  <img class="menu-icon" src="img/hamburger.png" alt="">

  <ul class="menu">
    <li><a href="index.html#about-me">O mně</a></li>
    <li><a href="index.html#offer">Nabídka</a></li>
    <li><a href="instructions.html">Návody</a></li>
    <li><a href="gallery.html">Galerie</a></li>
    <li><a href="index.html#contact">Kontakt</a></li>
  </ul>
</nav>

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda