Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

417
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda