Home Web Front-end JS Tutorial Getting Started with JQurey - An Example of the Bubbling Phenomenon in Event Mechanism_jquery

Getting Started with JQurey - An Example of the Bubbling Phenomenon in Event Mechanism_jquery

May 16, 2016 pm 05:42 PM
event mechanism bubble

1. When the user browses the page , the browser will interpret or compile the page code - this process is essentially event-driven, that is, when the page is loaded, a Load event is executed. , in this event, the process of the browser compiling the page code is implemented. After the event is triggered, it is divided into two stages, one is Capture and the other is Bubbing. However, most browsers do not support the capture stage, so after the event is triggered, the bubbling process is often executed.

2. Sample code :

Copy code The code is as follows:





Bubbling in events











3. Rendering preview:


After clicking:

After clicking once, the number of execution times is shown to be 3 times. This is because the event has a bubbling phenomenon during the execution process, that is, although the click It's a button, but the event of the

element surrounding the button is also triggered. At the same time, the event of the element surrounding the
element is also triggered. The whole process is a bubbling process. How to prevent the bubbling process from happening can be achieved through the stopPropagation() method or return false. Modify the code as:

Copy code The code is as follows:



The effect picture is as follows:

After clicking
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is event bubbling? In-depth analysis of event bubbling mechanism What is event bubbling? In-depth analysis of event bubbling mechanism Feb 20, 2024 pm 05:27 PM

What is event bubbling? In-depth analysis of the event bubbling mechanism Event bubbling is an important concept in web development, which defines the way events are delivered on the page. When an event on an element is triggered, the event will be transmitted starting from the innermost element and passed outwards until it is passed to the outermost element. This delivery method is like bubbles bubbling in water, so it is called event bubbling. In this article, we will analyze the event bubbling mechanism in depth. The principle of event bubbling can be understood through a simple example. Suppose we have an H

Why do events fail to bubble up? Why do events fail to bubble up? Jan 13, 2024 am 08:50 AM

Why don't events bubble up in some cases? Event bubbling means that when an event on an element is triggered, the event will propagate upward from the innermost element until it is passed to the outermost element. But in some cases, the event cannot bubble, that is, the event will only be processed on the triggered element and will not be passed to other elements. This article will introduce some common situations, discuss why events fail to bubble, and provide specific code examples. Use the event capture pattern: Event capture is another way of event delivery, as opposed to event bubbling.

Master the common event bubbling mechanism in JavaScript Master the common event bubbling mechanism in JavaScript Feb 19, 2024 pm 04:43 PM

Common bubbling events in JavaScript: To master the bubbling characteristics of common events, specific code examples are required. Introduction: In JavaScript, event bubbling means that the event will start from the element with the deepest nesting level and propagate to the outer element until it propagates to The outermost parent element. Understanding and mastering common bubbling events can help us better handle user interaction and event handling. This article will introduce some common bubbling events and provide specific code examples to help readers better understand. 1. Click event (click

Which JS events are not propagated upward? Which JS events are not propagated upward? Feb 19, 2024 am 08:17 AM

Which JS events will not bubble? In JavaScript, event bubbling means that when an element triggers an event, the event will bubble up to higher-level elements until it bubbles to the document root node. The event handlers are then executed in the order they bubble up. However, not all events bubble up. Some events will only execute the event handler on the target element after being triggered, without bubbling up to higher-level elements. Here are some common events that do not bubble: focus and blur events:

Why does the same event trigger bubbling twice? Why does the same event trigger bubbling twice? Feb 19, 2024 pm 10:34 PM

Why does the same bubbling event happen twice? Event bubbling is a common event delivery mechanism in browsers. When an element triggers an event, the event will be passed from the triggered element to the upper elements in sequence until it is passed to the root element of the document. This process is like bubbles bubbling in water, so it is called event bubbling. However, sometimes we find that the same bubbling event occurs twice. Why is this? There are two main reasons: event registration and event processing. First, we need to make it clear that the event

Capture first or bubble first? Analyze the advantages and disadvantages of event processes Capture first or bubble first? Analyze the advantages and disadvantages of event processes Feb 21, 2024 pm 02:36 PM

Capture first or bubble first? Analyzing the advantages and disadvantages of event process Event process is an important concept in web development. It describes the process of events from occurrence to processing. There are two main process models when handling events: capture then bubble and bubble then capture. These two models have their own advantages and disadvantages in different scenarios, and you need to choose the appropriate model based on the actual situation. Capturing first and then bubbling means that the event capturing phase is executed before the event bubbling phase. The event capture phase starts from the root node of the event target and passes down step by step until it reaches the target element.

Explore click event bubbling and master the key principles of front-end development Explore click event bubbling and master the key principles of front-end development Jan 13, 2024 am 10:56 AM

Learn click event bubbling and master key concepts in front-end development. Specific code examples are required. Front-end development is an important field in today's Internet era, and event bubbling is one of the key concepts in front-end development. Understanding and mastering event bubbling is critical to writing efficient front-end code. This article will introduce what event bubbling is and how to use the concept of event bubbling in front-end development. 1. What is event bubbling? Event bubbling means that when an event on an element is triggered, it will start from the innermost element first, and then proceed to the parent element step by step.

Master the event mechanism of ThinkPHP6 Master the event mechanism of ThinkPHP6 Jun 21, 2023 am 11:51 AM

As web applications continue to expand in size, how to better handle events has become the key to our development. ThinkPHP6 provides an event mechanism that can help us better handle events in web applications. The Role of Event Mechanism in Web Applications Event Mechanism is an application design pattern that involves designing an application as an event-driven system. Specifically, an event is a "trigger" that when an event occurs, the associated code is activated and executed. The role of event mechanism in web applications

See all articles