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

127
Vistas
emit events to all child nodes of a html dom element

I need to emit an event to all deep childNodes of an element. What i am looking is event capturing using custom events or something equivalent.

one of the solution is to recursive loop through all children and then emit events to each one, but it is slower.

is there any better solution ?

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

0

Not sure what you mean with deep childNodes, but querySelectorAll can select all elements at any nesting level starting from a root node:

const elems = root.querySelectorAll("*")
const customEvent = new CustomEvent('custom')

elems.forEach(el => {
el.addEventListener("custom", (e) => console.log("Custom event received on element:", e.currentTarget))
el.dispatchEvent(customEvent)
})
<div id="root">
  <button>B1</button>
  <p>P1</p>
  <div>
    <p>P2</p>
    <p>P3</p>
    <button>B2</button>
  </div>
</div>

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