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

421
Visualizações
How get the href of each class and store it inside a list (javascript)?

There is a list I have with 7 entries. On the picture below you can see the area which I marked purple: 6 entries. You see the area which I marked blue, all the 7 entries got the same <a class "FPmhX notranslate MBL3Z". My question is how can I get the href of each entry and store them all in a list/array? In this example, the href of first entry is /foo.96/.

If my question is not clear please tell me and I will try to describe it differently! :)

enter image description here

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

0

Create parent element of list in html and in your javascript write:

var links = document.querySelectorAll("a.FPmhX.notranslate.MBL3Z");
var list = document.querySelector("ul#linkList");///Your path to parent

for(var i=0;i<links.length;i++){
    list.innerHTML += "<li>" + links[i].href + "</li>";
}

Or if you want to get the pathname then use links[i].pathname instead of links[i].href.

Here's the snippet

var links = document.querySelectorAll("a.FPmhX.notranslate.MBL3Z");
var list = document.querySelector("ul#linkList");

for(var i=0;i<links.length;i++){
    list.innerHTML += "<li>" + links[i].href + "</li>";
}
<a href="https://www.w3schools.com/" class="FPmhX notranslate MBL3Z"></a>
<a href="https://developer.mozilla.org/en-US/" class="FPmhX notranslate MBL3Z"></a>
<a href="https://stackoverflow.com/questions" class="FPmhX notranslate MBL3Z"></a>
<a href="https://css-tricks.com/" class="FPmhX notranslate MBL3Z"></a>
<ul id="linkList">
  Links:
</ul>

Is it helpful? :)

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