Event bubbling: the deepest element of event promotion first receives events. Then, the parent element of the object goes up until the document Object finally receives the event. Although a document does not have an independent visual representation relative to an html element, it is still the parent element of an html
specific element.
The above example occurs under the concept of event capture the order of click events should be document-> HTML-> body-> div-> P
AddEventListener's third argument
The event flow specified in "DOM2-level events" supports both the event capture phase and the event
JavaScript event bubbling and event delegationJiang Jianyu-2 reviewsIt's not too much to learn before you touch JavaScript. Light rain is the habit of the usual learning to share things out. On the one hand to strengthen their impressions, on the one hand can let their exper
, or XMLHttpRequest.
The type string, the event name, does not contain "on", such as "click", "MouseOver", "KeyDown", and so on.
Listener implements a EventListener interface or a function in JavaScript.
Usecapture whether to use snapping, look at the next event stream after a while to understand, generally with false
1. Event bubblingMicrosoft has proposed an event flow called event bubbling. Event bubbling can be figuratively likened to putting a stone into the water, and bubbles will come up from the bottom. That is, the
When using JS, when the same event is defined for the child element and parent element, such as the onclick event is defined, and when the child element is clicked, the OnClick event of the parent element is also triggered. JS says the mechanism for this event to occur continuously is
(element.attachevent) {Element.attachevent (' on ' +type,handler);}else{element[' on ' +type]=handler;}},Delete HandleRemovehandler:function (Element,type,handler) {if (Element.removeeventlistener) {Element.removeeventlistener (Type,handler,false);}else if (element.detachevent) {Element.detachevent (' on ' +type,handler);}else{element[' on ' +type]=null;}},Get this eventGetevent:function (event) {return event
Talking about JavaScript events, event bubbling, event capture, and blocking default events are three topics that can be difficult to avoid, whether in an interview or in a normal job.Bubble article:Let's take a look at some examples:Js: var$input = document.getElementsByTagName ("input")[0]; var$div = document.
I. Sequence of occurrences
The origin of this problem is very simple, assuming you have another element nested within one element
Copy Code code as follows:
-----------------------------------
| element1 |
| ------------------------- |
| |element2 | |
| ------------------------- |
| |
-----------------------------------
: And both have an OnClick event handler function (event
Focus EventOnfocus: Getting focusOnblur: Losing focusEvent bubbling (and style independent, structure)When an element receives an event, it propagates all the events he receives to his parent, always to the top windowBlock bubbling:Called in the event function that currently wants to block bubblingEvent.cancelbubble=true; Current object that blocks the current ev
+ ', ' +event.clienty);//Gets the position of the click, in pixels, the sub-notation may appear incompatible issues//Incompatible Hint: Reffereceerror event is not definedThe compatible wording is as follows:Console.log (e.clientx+ ', ' +e.clienty);/* Gets the writing of the event source (that is, the target node of the event)IE:event.srcElementFire Fox:event.tar
often becomes a tricky problem for programmers who are not familiar with event bubbling. So when necessary, we want to stop the event bubbling."Do not want to activate the event is activated example"DivOnClick= "Openwin (' http://www.baidu.com ')"Id= "OutSide"Style= "width:
child element Register Click eventVarparent = document.getElementById ("parent"); Varchild = document.getElementById ("Child"); Parent.onclick=function (e) {if (e.target.id = = "Child") {Console.log ("You clicked on the child Element")}}Although there is no direct only child element to register the click event, a prompt message pops up when the child element is clicked.To here you do not have JS of the event
This article mainly introduces javascript event bubbling and javascript implementation code to prevent event bubbling. If you are interested, you can refer to the event as one of the co
program disorder and even failed debugging, this is often a tricky issue for programmers who are unfamiliar with event bubbling. So when necessary, we need to prevent event bubbles. [Example of activation of events that do not want to be activated]
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> Div Onclic
also supports text node event bubbling.Event captures reach the top level of the target in different browsers or different browser versions also have a difference. In IE6, HTML is a receive event bubbling, and most browsers continue bubbling to the Window object, which is ... body→documen→window.Blocking bubbles does
This article mainly introduces the principle of javascript event bubbling. The example analyzes the definition and implementation skills of event bubbling. If you need it, you can refer to the example below to describe javascript
This article mainly introduces the principle of javascript event bubbling. The example analyzes the definition and implementation skills of event bubbling. if you need it, you can refer to the example below to describe javascript
to implement this function, in the DIV1 click, pop-up "Hello, I am the outermost div." "Hello, I'm a second-tier div" when clicked on Div2, "Hello, I'm span." "。
From this we will have the following JavaScript fragment:
Expect the above code to click Span when it comes out a pop-up box "Hello, I am span." "Yes, it does pop up such a dialog box:
However, not only will this dialog box be generated, but when the click is OK, the follo
However, in some large WEB interaction projects today, such as large WebGame projects, the influence of JavaScript event bubbling is worth noting. This article uses a simple example to explain the JavaScript event bubbling and pre
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.