-
dom object from the beginning of the outermost layer, layer by layer down is not bound recorded the event on each target dom, if there is recorded
Execution order: until the target element from the outer to the inner OFF
-
The event target event triggers
Target element of the event trigger
-
Event bubbling
From the start of the target element, bubbling up layer by layer trigger (record-bound stage capture event)
Execution sequence: from the inside
1, when the same event ancestor and descendant elements are bound descendant elements of an event triggers, events will trigger ancestor element
2, the event ancestor, descendant elements can trigger (descendant elements is not bound to the event)
Event listeners:
el.addEventListener ( 'event name', fn [, true / false]);
Third: whether in the capture phase advance trigger defaults to false
How to stop event bubbling
dom Standard:
calling the next event object a method can prevent
e.stopPropagation ()
IE under
e.cancelBubble = true; Compatibility wording: IF (e.stopPropagation) { e.stopPropagation () } {the else e.cancelBubble = true; } trinocular e.stopPropagation e.stopPropagation ():? = e.cancelBubble to true; a try..catch () the try { e.stopPropagation (); } the catch () { e.cancelBubble = to true; }
Prevent the default event
e.preventDefault()
Event delegates
Principle: use event bubbling, the event will execute the implementation of sub-elements, added to the parent element, the parent element entrust execution