4

I am using a jquery plugin which binds a click event on certain elements.

I know that the plugin uses

e.stopPropagation();

but I also want to have my own events when clicking on those elements.

Is there a way to make the plugin's stopPropagation be inactive, or to have my event have priority over the plugins bind?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244
  • possible duplicate of [Priority when more than one event handler is bound to an element](http://stackoverflow.com/questions/8779657/priority-when-more-than-one-event-handler-is-bound-to-an-element) – Boaz Apr 24 '14 at 07:52
  • 1
    `stopPropagation` will only *'Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event'*. But *'will not prevent other handlers on the same element from running'*. See http://api.jquery.com/event.stoppropagation/ – haim770 Apr 24 '14 at 07:55

3 Answers3

2

e.stopPropagation() stops an event from propagating UP to parent objects. It does not block other event handlers attached to the same object from firing.

So, if you want other event handlers on the object, you can just attach them directly and they will not be affected by the e.stopPropagation() at all. You will just need to make sure you are attaching your own events to the actual source object of the event, not to a parent object.

In answer to another part of your question, the only way to prevent the e.stopPropagation() call is to remove the event handler that's calling it or modify the plug-in's code to remove that line. But, fortunately, you can have your own functioning event handlers on the object without doing either of these.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
0

Add on click event to your element as below it will 1st call your on click event then event bubble up to other events attached by plugins

$("#element").on("click", function(){
   alert('my event called');
});
HKumar
  • 655
  • 1
  • 8
  • 18
  • It will give priority of his own event over plugin added event, after this eventually plugins event will be called, Created [jsfiddle](http://jsfiddle.net/hikumar/eMf2M/) here I am adding a event at dom ready and again another event on click. – HKumar Apr 24 '14 at 08:04
0
Event.prototype.stopPropagation = null;
Ryan
  • 14,392
  • 8
  • 62
  • 102