Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!