Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

194
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda