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

117
Views
How do I change multiple elements with the same class to a list of array items

Basically, I have multiple elements with the same class name, what I am doing is fetching an array of integers from an API, I want to loop through all the elements with this class name and change each one to one of the elements from the array in order. For example

<p class="test">hello</p>
<p class="test">hello</p>
<p class="test">hello</p>
<p class="test">hello</p>

and the array looks like this [1,5,2,11] after the loop, things should look like this

<p class="test">1</p>
<p class="test">5</p>
<p class="test">2</p>
<p class="test">11</p>

Thank you)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Loop through the array indexes. Then use that index to access the corresponding array elements and DOM elements.

const array = [1, 5, 2, 11];
const paras = document.getElementsByClassName("test");

array.forEach((val, i) => paras[i].innerText = val;
about 4 years ago · Juan Pablo Isaza 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!