Home >Web Front-end >JS Tutorial >In-depth analysis of js bubbling events_Basic knowledge
When doing DOM operations in JavaScript, you will definitely encounter js bubbling events. The most common one is the div pop-up event as shown in the illustration
When you click on the gray part, the pop-up window disappears, but when you click on the black part, it has no effect.
Use the following code to analyze js bubbling events
html code:
Illustration:
When the button is clicked, "I am button" will pop up and then "I am div" will pop up, because the button event is triggered first and then the next layer div click event is triggered,
Illustration:
Then sometimes we don’t want multiple events to trigger and cause conflicts, so events have stopPropagation(); methods to prevent bubbling
The example code is as follows