0

There are more custom onclick events on a page. I want for every custom onclick event to first prevent the default, do my things and then pass the command to the first custom event.

In other words I want to put my event on top of any other assigned click events. How can I do that?

Octavian
  • 4,519
  • 8
  • 28
  • 39

1 Answers1

0

You may see this answer.

OR

Refering to this explanation you can choose where to get involved in the event-dispatching-process.

It states clearly

In the browsers that support the W3C DOM, a traditional event registration
element1.onclick = doSomething2;
is seen as a registration in the bubbling phase.

So you have to hook into the capturing phase:

element.addEventListener('click', function() {
    //do your stuff
},true);

This way your event is on top of other assigned click events.
But it is still a question, if the browser supports this kind of event handling.

Community
  • 1
  • 1
KeyNone
  • 8,745
  • 4
  • 34
  • 51