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

165
Views
Cambiar el href de una etiqueta

Estoy haciendo un script de usuario para Instagram . Lo que quiero hacer es cambiar el href de una etiqueta <a> . Esta etiqueta no tiene ningún ID/clase. ingrese la descripción de la imagen aquí

Ya encontré cómo seleccionarlo:

 var x = document.querySelector(".oJZym").getElementsByTagName("a"); x[0]

Quiero que abra una nueva pestaña en https://instagram.com/nukl3ar_p/ . Ya he probado:

 var x = document.querySelector(".oJZym").getElementsByTagName("a"); x[0].href = "https://instagram.com";

o

 var x = document.querySelector(".oJZym").getElementsByTagName("a"); x[0].onclick = window.open("https://instagram.com/nukl3ar_p/", "_blank");

Pero me sigue redirigiendo sin siquiera haber hecho clic en él. ¿Como arreglar?

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

0

Intente esto, use el Selector de CSS > para obtener el elemento secundario <a> y luego configure href.

 var x = document.querySelector(".oJZym>a"); x.href = "https://instagram.com/nukl3ar_p/"; x.target ='_blank';
 <div class="oJZym" ><a href="/">Test</a></div>

about 4 years ago · Juan Pablo Isaza Report

0

Puede usar la biblioteca d3 para modificarlo así:

 <script src="https://cdn.jsdelivr.net/npm/d3@7"></script> <script> const div = d3.select(".oJZym").select("a") .attr("href","https://instagram.com/nukl3ar_p/") .attr("target","_blank"); </script>

Este script utilizará la biblioteca d3 para seleccionar el hipervínculo dentro de la clase ".oJZym" y establecer su href y atributo de destino.

about 4 years ago · Juan Pablo Isaza Report

0

Prueba estas lineas..

 var x = document.querySelector("oJZym + a") x[0].href = "https://instagram.com";
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!