Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda