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

202
Vistas
How to select specific item with class from Nodelist?

let's say I have my HTML document like

<a href='#' class='class_1'>Content</a>
<a href='#' class='class_2'>Content</a>
<a href='#' class='class_3'>Content</a>
<a href='#' class='class_4'>Content</a>
<a href='#' class='class_5'>Content</a>

Now, I have selected those anchor tags with querySelectorAll and looped through them using forEach.

Inside forEach, after calculating some stuff, I need to apply a style to a specific anchor tag with its class.

anchorList.forEach(link => {})

How can I select that link with a certain class without using another loop?

Question might be little unclear, feel free to ask anything needed
about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

Since you are already looping through all of the anchor tags using a forEach, you can check for the specific class in the loop itself. Try this code:

var anchorList = document.querySelector("a");

anchorList.forEach(link => {
  // calculations...
  if(link.className === "class_1"){
    link.style.color = "red"; // or anything else
  }
  // continue calculations...
});

Don't hesitate to comment if something is incorrect or not what you were asking for, I'll update my answer.

about 4 years ago · Santiago Gelvez 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