Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does jQuery event model does not support event Capture and just supports event bubbling

Tags:

jquery

Why does jQuery event model does not support event Capture and just supports event bubbling?

like image 871
sushil bharwani Avatar asked Aug 23 '11 15:08

sushil bharwani


People also ask

What is the difference between event bubbling and event capturing?

Event Bubbling − Whenever an event happens on an element, the event handlers will first run on it and then on its parent and finally all the way up to its other ancestors. Event Capturing − It is the reverse of the event bubbling and here the event starts from the parent element and then to its child element.

What is event bubbling in jquery?

Event bubbling directs an event to its intended target, and works like this: When an object (like a button) is clicked, an event is directed to the object. If an event handler is set for the object, the event handler is triggered. Then the event bubbles up (like a bubble in water) to the objects parent.


2 Answers

Because not all browsers support event capturing, especially IE. As jQuery is supposed to be cross-browser compatible, it cannot offer event capturing (it might be possible to simulate event capturing, but if it were easy, I'm sure they would have done it).

like image 136
Felix Kling Avatar answered Oct 09 '22 02:10

Felix Kling


This was infact a desirable feature in jQuery 2 but the core-team was pretty much convinced that allowing capturing events to have equal standing throughout the entire jQuery event system would open up a whole lot of issues. The original ticket can be found here[1]. They even closed the ticket after few discussions.

Moreover, browsers older then IE8 and Opera 7.0 does not support event capturing. Since the primary goal of jQuery is to provide cross-browser support, it does not support event capturing.

On a lighter note, it seems jQuery is more focused to leverage Event Delegation which is based on bubbling of events up to the DOM tree.

[1] http://bugs.jquery.com/ticket/14953

like image 30
nalinc Avatar answered Oct 09 '22 03:10

nalinc