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

175
Visualizações
Change a tag's href

I'm making an userscript for Instagram. What I want to do is to change an <a> tag's href. This tag doesn't have any ID/class.enter image description here

I already found how to select it:

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

I want it to open a new tab to https://instagram.com/nukl3ar_p/ . I've already tried:

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

or

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

But it keeps redirecting me without even having clicked it. How to fix?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Try this, use CSS Selector > to get the child <a> then set 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 Relatório

0

You can use the d3 library to modify it like this:

<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>

This script will use the d3 library to select the hyperlink within the ".oJZym" class and set its href and target attribute.

about 4 years ago · Juan Pablo Isaza Relatório

0

Try these line..

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