Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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');
});
Event.prototype.stopPropagation = null;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top