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

120
Visualizações
Event Delegation on html elements

I have HTML div with class wrapper_menu, the div class mainBlock is generated trought JS class and appended to wrapper_menu.

The task is to get addEventListener on wrapper_menu to delegate it and call it when any part of mainBlock is clicked, then to use mainBlocks id to call function depending on id.

The problem is when I get such construction, in console.log it shows me children elements too if i click on them (because obviously they are there), I have tried to use eventcurrentTarget.children but it doesnt let work with them since they are HTMLcollection.

is there a way to use delegation here without Jquery? I can use onclick medthod or add eventlistener to each mainBlock but the idea was to implement delegation.

Thank you for help

wrapper_menu.addEventListener("click", (e) => {
 console.log(e.target);
})

<div class="wrapper_menu">
    <div class="mainBlock" id="1"> <div class="block">
         <div class="ddTopic">
             <img class="book" 
             <span class="item_title"></span>
             <span class="item_description"></span>
         </div>
    </div>
</div>
about 4 years ago · Juan Pablo Isaza
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