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

153
Views
cómo reemplazar el enlace href usando javascript

Tengo muchas páginas con muchos enlaces. Quiero reemplazar algunos enlaces específicos con otro enlace.

lo que deseo hacer aquí es encontrar el atributo href de <a> y reemplazarlo con el enlace deseado

Aquí está el código HTML

 <div class="one"> <div class="item"> <a href="somelink.com">click</a> </div> </div>

y quiero cambiar HTML a

 <div class="one"> <div class="item"> <a href="replacedlink.com">click</a> </div> </div>
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Prueba esto

 $('.item a').attr('href').replace('somelink.com', "replacedlink.com");

O

 $(".item a[href='somelink.com']").attr("href", "replacedlink.com");

Con jQuery 1.6 y superior, debe usar:

 $(".item a[href='somelink.com']").prop("href", "replacedlink.com");
about 4 years ago · Santiago Trujillo Report

0

Una forma podría ser usar el valor href para encontrar el ancla

 var a = document.querySelector('a[href="somelink.com"]'); if (a) { a.setAttribute('href', 'replacedlink.com') }
 <a href="somelink.com" title="this link"> </a>

about 4 years ago · Santiago Trujillo Report

0

Prueba esto:

 $(".item a[href='somelink.com']").attr('href','replacedlink.com');
about 4 years ago · Santiago Trujillo 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!