0

Is there a way to trigger a custom event in javascript, so that it will propagate using the capture model?

I have a hierarchy of elements that I use as a mean to communicate between objects. Each level of the hierarchy represents a sub-family of object. Ideally, I could trigger an event to each family's or sub-family's objects using their common ancestor.

eg:

animals |_ | mammals | |_cats | |_dogs |_ reptiles |_alligators |_dinosaurs

(please no comments on my inadequate taxonomy :) )

I would like to be able to trigger an event for all animals, all mammals or all cats, or event to a single cat instance.

However, I can only find examples of custom events using the bubbling phase, so I want to know if it's me missing something or is this really impossible.

I know I can use event delegation on the root element for all instance, but it will scale really badly (this system needs to handle thousands of events of all types).

Any ideas?

AriehGlazer
  • 2,220
  • 8
  • 26
  • 29
  • In essence, you are trying to register one event handler per group, instead of attaching to each object within? – JNF Sep 01 '14 at 08:43
  • As one of the use cases - yes. I want to be able to trigger an event for any group of decendants through their parent, without the need to iterate through each of them to trigger it manually on each instance – AriehGlazer Sep 01 '14 at 16:41
  • Did you ever find a solution? – Michael May 12 '16 at 22:18

1 Answers1

1

This is not possible with current DOM event specification, as it only supports the bubble phase.

AriehGlazer
  • 2,220
  • 8
  • 26
  • 29