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

159
Views
How do i swap the old links in my a links href attribute values with the ones in my newLink array?

I've been trying to get my a links to get the attribute value from my newLink array as it new attribute value to no avail. Any help would be welcome.

<ul id="ul">
    <li><a href="https://www.google.com/">GOOGLE</a></li 
    <li><a href="https://www.amazon.com/">AMAZON</a></li> 
    <li><a href="https://www.ebay.com/">EBAY</a></li>
    <li><a href="https://www.pointekonline.com/">POINTEK</a></li>
  </ul>
ul.onclick = function (e) {
      let newLink =["https://www.barcablaugranes.com/","https://managingmadrid.com/","https://bavariafootballwork.com/","https://wagnh.com/"]
      let ass = querySelectorAll('a');
           if (e.target.nodeName != 'A') return;
            for(let i = 0; i < ass.length; i++){
              return ass[i].href = links[i]
            }
           return false;
         }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You had errors in your code. I have fixed them. Now it should be working.

Your Errors

  • Why wouldn't want the links to be updated as soon as the site is loaded?
  • Why looking for event target.nodeName without preventing the default behaviour of links?
  • Why using return in event listener?
  • Missing document before querySelector

let newLink = ["https://www.barcablaugranes.com/", "https://managingmadrid.com/", "https://bavariafootballwork.com/", "https://wagnh.com/"]
let ass = document.querySelectorAll('a');
for (let i = 0; i < ass.length; i++) {
  ass[i].href = newLink[i]
}
<ul id="ul">
  <li><a href="https://www.google.com/">GOOGLE</a></li>
  <li><a href="https://www.amazon.com/">AMAZON</a></li>
  <li><a href="https://www.ebay.com/">EBAY</a></li>
  <li><a href="https://www.pointekonline.com/">POINTEK</a></li>
</ul>

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!