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

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

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