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

250
Vistas
How to iterate through <ul> child elements using DOM JS

So I have a menu, I want it to display information accordingly, for example:

<ul id="menu-list">
  <li id="about-me"><a href="#">About Me</a></li>
  <li id="skills"><a href="#">Skills</a></li>
  <li id="experience"><a href="#">Experience</a></li>
  <li id="education"><a href="#">Education</a></li>
  <li id="projects"><a href="#">Projects</a></l>
  <li id="contacts"><a href="#">Contacts</a></li>
</ul>

and on my JS file I did this in order to access "li" elements:

let navMenu = document.getElementById("menu-list");
let menuList = navMenu.getElementsByTagName("li");

let skillsButton = document.getElementById("skills");
let skillsEvent = document.getElementById('main-section-skills').hidden = true; 
(text that will display on click is pre-set to hidden = true)

The goal is to iterate through "li" items to find which one of those has ".hidden = false" value and change it to ".hidden = true" so that when you click on different menu buttons, each button will so only relevant info and others that are not relevant will bi hidden.

Thanks for your help.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can get the array of children using element.children

https://developer.mozilla.org/en-US/docs/Web/API/Element/children

for (let child of navMenu.children) {
   your logic here
}

For checking the class you can use element.hasClass or even:

 element.style.display = 'none'
 element.style.display = 'block'
about 4 years ago · Juan Pablo Isaza Denunciar
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