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

263
Vistas
Why is the element undefined when I iterate through all elements with a tag?

So whenever I run my code this

const sections = document.getElementsByTagName("section");
let colors = ["#ffc933", "#09ff00", "#00ccff", "#2b72ff", "#5436ff", "#dd54ff", "#5a0070", "05c9ff", "ff5405", "fa2d2d"];
for(ele in sections)
{
    console.log("Yes");
    ele.style.backgroundColor = colors[Math.floor(Math.random() * 10)];
}

it always returns an error saying that the property style of ele can't be assigned to since it is undefined. This doesn't make any sense to me since it says for the elements in sections so all the ones that are there should be iterated through so nothing should be undefined.

about 4 years ago · Juan Pablo Isaza
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