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

145
Vistas
JavaScript ListItem onClick issue

I'm working on a web-app in HTML and JS and I need to catch the clicks on each listItem of a list. The list is dynamically created in a for-loop as follows:

var i = document.createElement("li");
i.innerHTML = "something"
uList.appendChild(i);

How can I make listItems clickable or catch clicks on each of them separately (get the specific item clicked)? I've tried adding an eventListener on the list, and then isolate the target of the event (click). The problem is that this would count as many clicks as the size of the list.

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

0

Bind the onclick listener to the new element.

i.onclick = () => {
    console.log('hi');
};
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