Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda