Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
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 Respostas
Responde à pergunta

0

Bind the onclick listener to the new element.

i.onclick = () => {
    console.log('hi');
};
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda