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

184
Views
Getting value from the custom nav bar

I'm working on the web page where I want to filter products by taking values from the nav bar using JS, like this:

<nav id="shop-nav" class="nav">
        <li> value="1">Something</li>
        <li> value="2">Something</li>
        <li> value="3">Something</li>
        <li> value="4">Something</li>
    </nav>

My JS code is:

for (let i = 0; i < categories.length; i++) {
    const link = document.createElement('li')
    link.innerHTML = categories[i].name
    link.value = categories[i].id
    nav.appendChild(link)
}

I know that this is possible with <select></select> tag, but I want to do it with the custom nav bar. Thanks

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

0

I ran the code you provided and there is an error having to do with categories. Where is categories coming from? Thanks!

Also, I made a small update in the HTML, below.

Blockquote Uncaught ReferenceError: categories is not defined

for (let i = 0; i < categories.length; i++) {
    const link = document.createElement('li')
    link.innerHTML = categories[i].name
    link.value = categories[i].id
    nav.appendChild(link)
}
<nav id="shop-nav" class="nav">
        <li value="1">Something</li>
        <li value="2">Something</li>
        <li value="3">Something</li>
        <li value="4">Something</li>
    </nav>

about 4 years ago · Juan Pablo Isaza Report

0

I may be misunderstanding please correct me if I am. But if you want to get the values from the navbar, you can use queryselector.

let navBarChildren = document.querySelector("nav[id='shop-nav']").children
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!