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

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