Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

243
Views
Cómo iterar a través de <ul> elementos secundarios usando DOM JS

Entonces tengo un menú, quiero que muestre información en consecuencia, por ejemplo:

 <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>

y en mi archivo JS hice esto para acceder a los elementos "li":

 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)

El objetivo es iterar a través de los elementos "li" para encontrar cuál de ellos tiene el valor ".hidden = false" y cambiarlo a ".hidden = true" para que cuando haga clic en diferentes botones de menú, cada botón solo sea relevante La información y otras que no sean relevantes se ocultarán.

Gracias por tu ayuda.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede obtener la matriz de niños usando element.children

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

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

Para verificar la clase, puede usar element.hasClass o incluso:

 element.style.display = 'none' element.style.display = 'block'
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!