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

101
Views
document.getElements and ejs files

I noticed the document.getElements is not working for ejs files. as in below code, I need to display: none the div class="delegate".

myscripts.js

document.getElementsByClassName("delegate").style.display="none";

index.ejs

<div class="delegate"> 

<p>helooo</p>
</div>

the error message shows in browser: Cannot set properties of undefined (setting 'display')

can you please help me to understand.

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

0

You're selecting a collection of nodes (actually an HTMLCollection) but trying to treat them as a single item. The collection doesn't have a display property, hence the error message.

You'll need to loop through them all and set the style individually. One way to do this is to convert the array-like HTMLCollection to an array first (using Array.from, or the spread opertor [...]) and then use Array.forEach to update each item:

[...document.getElementsByClassName("delegate")].forEach(el => el.style.display='none')
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!