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

236
Visualizações
How to get href using innertext and regex

How to get Href from the <a> tag.

how to get href link using selectors, I have tried like below but it didn't work.

expected to get "www.test.com/all_reviews"

var a = document.querySelectorAll("a[href =*'all_reviews'*]")
console.log(a)
<a href="www.test.com/all_reviews">All Reviews</a>
<a href="www.test.com/all_reviews/altered">All Reviews</a>

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

0

To access the href you should use getAttribute of the selected element

let anchors = document.querySelectorAll('a[href*="all_reviews"]');
let link = null;
Array.from(anchors).forEach(element => {
    let pattern = /all_reviews$/;
    let url = element.getAttribute('href');
    if(pattern.test(url)) {
      link = url;
    }
});

console.log(link);
<a href="www.test.com/all_reviews">All Reviews</a>
<a href="www.test.com/all_reviews/altered">All Reviews</a>

You can use a Regular expression which check if the link and with all_reviews as the second link all_reviews is not at the end of the URL.

about 4 years ago · Juan Pablo Isaza Relatório

0

You could use the jquery :contains() selector like this:

 $("a:contains(All Reviews)") 

See a code example and read more about it here: https://api.jquery.com/contains-selector/

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