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

244
Views
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 answers
Answer question

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