1

Here as in image showing the click events bound to a particular element.

enter image description here

The a.interstitial handler is attached using jQuery. The body handler is attached using addEventListener() (I think, that code is obfuscated and hard to read).

I would like to cancel the "body" event handler execution in my "a.interstitial" handler, but I can't because for some reason the body handler always runs first. This is contrary to my understanding of how event bubbling works. Shouldn't the more specific ("a.interstitial") handler be run before the body handler?

mhenry1384
  • 7,538
  • 5
  • 55
  • 74
  • 1
    Basically, events are two-way affairs. You've got one direction, bubbling, but you're missing capturing (or propagation). See [What is event bubbling and capturing?](https://stackoverflow.com/a/4616720/215552) – Heretic Monkey Aug 29 '19 at 14:49

1 Answers1

1

As you mentioned body is registered through addEventListener. Can you check in addEventListener call if the third argument is set to true. If so it will be dispatched to the registered listener before being dispatched to any EventTarget

Refer https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener

In this case, body function gets executed first then the click action of anchor takes place.