Re:JavaScript useCapture demystified
by kaio on Monday March 04, 2013 @06:05AM
(#5317662)
Makes me wonder if there are any good reasons to support both [capturing, bubbling] ways of event propagation. I think the default W3C model does a pretty good job and is more consistent with the concept of the DOM _tree_
Mixing these two modes also seems to be a good source for hours of bughunting :~
There's also the "browser default" behavior, which is stuff like highlighting selected text. That does happen after the event finishes bubbling. (Usually.)
Note that stopping an event from bubbling (with `event.stopPropagation()`) and stopping an event's default behavior (with `event.preventDefault()`) are two separate, unrelated actions. However, returning false from an event handler is equivalent to doing both.
http://www.quirksmode.org/js/events_order.html
This is not quite correct. The event will fire as it bubbles upward, not after it reaches the document level.
The DOM Events Level 3 specification has a helpful diagram:
http://www.w3.org/TR/DOM-Level-3-Events/#event-flow
There's also the "browser default" behavior, which is stuff like highlighting selected text. That does happen after the event finishes bubbling. (Usually.)
Note that stopping an event from bubbling (with `event.stopPropagation()`) and stopping an event's default behavior (with `event.preventDefault()`) are two separate, unrelated actions. However, returning false from an event handler is equivalent to doing both.
1. maybe an initial syntax overview: target.addEventListener(type, listener[, useCapture]);
2. I think it’d be worth explaining what capture and bubble are.
I agree!
Did like this post though, I've only recently picked up JS and this confused me when I tried implementing listeners a few weeks ago for a project.