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

262
Views
how to redirect to a link wich is defined in child selector

I want to redirect on the click of the item

EX: class="nav-item" data-nav-item="1"

to the link which is defined in his child tag "a"

<div class="nav-item" data-nav-item="1">
  <div class="item-parent">
    <a href="https://mywebsite-men.com">MEN</a>
  </div>
</div>

<div class="nav-item" data-nav-item="2">
  <div class="item-parent">
    <a href="https://mywebsite-women.com">Women</a>
  </div>
</div>

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

0

You can use click to trigger click when the parent element is clicked

[...document.getElementsByClassName('nav-item')].forEach(item => {
  item.addEventListener('click', (e) => {
    item.querySelector('a').click()
  })

})
.nav-item {
  width: 50px;
  height: 20px;
  padding: 10px;
  border: 1px solid green;
  cursor: pointer;
}
<div class="nav-item" data-nav-item="1">
  <div class="item-parent">
    <a href="https://mywebsite-men.com">MEN</a>
  </div>
</div>

<div class="nav-item" data-nav-item="2">
  <div class="item-parent">
    <a href="https://mywebsite-women.com">Women</a>
  </div>
</div>

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!