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

101
Vistas
Why is this event handler from a class loop not responding?

I'm looping through 10 divs with the same class to add event handlers which should change the border on a mouse click. I'm using getElementsByClassName. There is no response to the click on any of the divs. The simple function worked on another div in an event handler.

The html:

<div class="note-small">
    <p>blah</p>
</div>

I used this vanilla JS:

const note_small_class = document.getElementsByClassName('note-small');

for (let i=0; i < note_small_class.length; i++) {
  note_small_class[i].addEventListener('click', () => {
    highlightNote(note_small_class[i]);
  })
};

function highlightNote(note) {
  note.style.background.color = 'red';
};

note_small_class shows as an object (HTML collection) in the console. Something isn't working, I would appreciate any help. Thank you.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

note.style.background.color = 'red';

There seems to be an issue with what you are setting the style to be, the property should be backgroundColor, not background.color, try this:

note.style.backgroundColor = 'red';
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