Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!