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

201
Visualizações
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 Respostas
Responde à pergunta

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