Concise understanding of js capture events and bubbling events

Link:
DOM's event delivery mechanism: capture and bubbling
.
Summary:

  1. When the third parameter of addEventListener is configured {capture: true }, it will happen when the capture event is triggered
  2. When the third parameter of addEventListener is configured {capture: false }, it happens when the capture bubbling is triggered
  3. Capture event occurs first, then bubbling event occurs
  4. Bubbling refers to triggering events from the child element to the parent element, and capturing is from the parent element to the child element
  5. The stopPropagation() method can not only prevent the event from bubbling, it can also prevent the event from being captured, or it can prevent it from being in the target phase.
  6. event.stopImmediatePropagation(): If multiple event listeners are attached to the same event type of the same element, when this event is triggered, they will be called in the order in which they were added. If stopImmediatePropagation() is executed in one of the event listeners, the rest of the event listeners will not be called.

addEventListener documentation .

stopImmediatePropagation document ;

Guess you like

Origin blog.csdn.net/qq_26889291/article/details/114917669