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

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

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