简体   繁体   中英

Can you chain overlapping click events in JS?

I was wondering whether it is possible to chain overlapping onClick events without passing anything down to the children.

I know I could just pass things down the tree and have a single function but I'm just experimenting

 <div onClick={()=> foo("a")} >
   <div onClick={()=> foo("b")} />
 </div>

what I want is receive the 2 events together in a listener function like:

listener = (events) => {
  console.log(events) // something like [[Event("a"), Event("B")], ......]
}

there's an "Event bubbling" concept. div inside another div and they both have a click listener for example, when you click the inner one you're basically clicking the outer one too. you can manage this behavior with 3rd argument of the addEventLister function, and also from inside the callback, e.stopPropagation()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM