Event stream —- Event bubble and event capture

Sometimes I have mixed feelings, but I have a lot of arguments. Those far away things seem to be yesterday,

The writer is painting the night, leaving passers-by in awe

Event flow-event bubbling and event capture

First of all, when we are talking nonsense, we need to understand one thing first, this thing is Event flow.


1. What is event flow?

  Explanation: When an HTML element triggers an event processing function, the event will be propagated from the element node to the root node, and the nodes through the propagation path will receive the event. This propagation process is called DOM Event flow.

   Simple explanation: When an element triggers an event, the propagation process is called an event flow.

  The event flow is divided into: event bubbling and event capture

2. What is event bubbling?
  Explanation: Event bubbling can be likened to throwing a stone into the water, and the bubble will always emerge from the bottom of the water, which means that the event will start from the innermost element and continue to spread upward. , Know the root node

  The incident raised by Microsoft is bubbling

3. What is event capture?
  Explanation: Suppose you are a disciple of the Crotch school and you have a conflict with others during the parade (assuming it is Miaofengfeng), then the people of Miaofengfeng will definitely find your sect in the first time. . Then after finding you, the master is finding you,
   Then shook hands with you and made peace (pure nonsense, in reality, you will definitely hit you even your mother doesn’t even know you). Such a search process is event capture

   Simple explanation: The process of event propagation from parent element to child element is called event capture

  The event capture proposed by Netscape

4. The order in which browser events are executed and propagated by default, first let’s take a look The sequence of event bubbling execution and execution

share picture

css

share picture

< p>

js

Share a picture

When we click oSmall, the order of event execution is: oSmall—->oBig—–>body—–document


Next, let’s look at the order of event capture execution and execution (css html code remains unchanged) 
js

share picture

When we click oSmall, the order of execution of events is: document—->body—- ->oBig—–oSmall

  Summary The default execution and propagation sequence of browser events is:   document----->html----->body-- --->.........---->The target element captures the process target element---->..... ....----->bo dy---->html---->document bubbling process

 First of all, when we are talking nonsense, we need to understand one thing first, and this thing is the flow of events.


1. What is event flow?

  Explanation: When an HTML element triggers an event processing function, the event will be propagated from the element node to the root node, and the nodes through the propagation path will receive the event. This propagation process is called DOM Event flow.

   Simple explanation: When an element triggers an event, the propagation process is called an event flow.

  The event flow is divided into: event bubbling and event capture

2. What is event bubbling?
  Explanation: Event bubbling can be likened to throwing a stone into the water, and the bubble will always emerge from the bottom of the water, which means that the event will start from the innermost element and continue to spread upward. , Know the root node

  The incident raised by Microsoft is bubbling

3. What is event capture?
  Explanation: Suppose you are a disciple of the Crotch school and you have a conflict with others during the parade (assuming it is Miaofengfeng), then the people of Miaofengfeng will definitely find your sect in the first time. . Then after finding you, the master is finding you,
   Then shook hands with you and made peace (pure nonsense, in reality, you will definitely hit you even your mother doesn’t even know you). Such a search process is event capture

   Simple explanation: The process of event propagation from parent element to child element is called event capture

   Incident capture proposed by Netscape

  Summarize the default execution and propagation order of browser events:   document----->html---- ->body----->.........---->The target element captures the process target element----> .........----->body---->html---->document bubbling process

Leave a Comment

Your email address will not be published.