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

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

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