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

262
Views
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
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!