showing results for - "what is event bubbling in javascript with example"
Federico
20 Apr 2020
1p {
2    line-height: 0;
3}
4
5div {
6    display:inline-block;
7    padding: 5px;
8
9    background: #fff;
10    border: 1px solid #aaa;
11    cursor: pointer;
12}
13
14div:hover {
15    border: 1px solid #faa;
16    background: #fdd;
17}
Leah
01 Apr 2019
1<script>
2	form.onclick = function(event) {
3  event.target.style.backgroundColor = 'yellow';
4
5  // chrome needs some time to paint yellow
6  setTimeout(() => {
7    alert("target = " + event.target.tagName + ", this=" + this.tagName);
8    event.target.style.backgroundColor = ''
9  }, 0);
10};
11</script>
12<html>
13<head>
14  <meta charset="utf-8">
15  <link rel="stylesheet" href="example.css">
16</head>
17
18<body>
19  A click shows both <code>event.target</code> and <code>this</code> to compare:
20
21  <form id="form">FORM
22    <div>DIV
23      <p>P</p>
24    </div>
25  </form>
26</body>
27</html>
28
29<!-- A handler on a parent element can always get the details about where it actually happened.
30
31The most deeply nested element that caused the event is called a target element, accessible as event.target.
32
33Note the differences from this (=event.currentTarget):
34
35event.target – is the “target” element that initiated the event, it doesn’t change through the bubbling process.
36this – is the “current” element, the one that has a currently running handler on it.
37For instance, if we have a single handler form.onclick, then it can “catch” all clicks inside the form. No matter where the click happened, it bubbles up to <form> and runs the handler.
38
39In form.onclick handler:
40
41this (=event.currentTarget) is the <form> element, because the handler runs on it.
42event.target is the actual element inside the form that was clicked. -->
queries leading to this page
how set online event handler capturingevent bubbling code javascriptjs event bubbling propagationwhat is event bubble in javascriptevent capturing in javascriptevent buublerevent bubble offevent bubbling vs event capturing in javascriptjavascript event bubbling best practicesevent bubllingjavascript bubbling eventcapture bubble eventbubble event jsaddeventlistener javascript bubblingjavascript object propagationjavascript bubbling vs capturinghow to change event target in javascript by event propagationbubbling year jsjavascript click event bubblingjavascrip event bubblinguse case of event bubling and capturingevent capture in javascriptbubble and capture phasewhat is the use of event bubbling in javascript with examplejavascript addeventlistener bubblingjavascipt event delagation bubblingaddeventlistener bubbledom bubbleevent capturing vs event bubblingaddeventlistener bubbling and capturingevent bubbling and capturewhich happens first bubbling or captureevent bubblesbubbling in jsevent bubbling in javascript tutorialwhat is the event bubble 3fwhat is meant by event bubbling 3fclick inside button event bublingwhat is event bubbling 3fcapture and bubble in addeventlistener in jsaddeventlistener bubblinghow to stop bubbling in javascriptjs describe event bubling and event capturingwhat is event capturingjavascriptevent bubbling javascrioptjavascript bubbling and capturingwhat 27s event bubbling 3fget element target indexevent bubbling issue examplebubbling phasejs detect all elements in event bubblejavascript bubblingevent bubblingjavascript event boublephases of dom eventshow to enable capturing javascriptevent bubbling in javascript exampleevent bubbles javascript target textget event capturing javascriptevent bubblingsevent bubbling vs event capturingbubbling phase jsjavascript addeventlistener bubbling stopjavascript event bubbling nedirjs bubbling phasebubbling in javascript meaningwhat is bubble event in javascriptboutton bubble up jswhat is bubbles in javascriptwhat is bubbling of eventbubbling in form jshow to check for event bubbling in javascriptevent bubbling and capturing w3schoolsjavascript stop bubblingjavascript repaint not attaching eventsevent bubbling in javascript explainedbubbling jscreate an onclick event that doesn 27t bubble upwaht is event bubblingjs event bubbling examplewhat is javascript bubblinghtml bubbling conceptwhat is event bubbling in javascriptjavascript bubbleswhat is javascript event bubblejs bubbling eventsevent propagation and event bubblingbubbling phase and capture phasejavascript event bubbling upevent bubbling example in jsdefine event bubbling in javascripthow propose bubbling jsstop bubbling in javascriptjavascript event bubbling conceptevents bubblingevent handling javascript bubblingwhat is event propagation in node jswhat is use of event bubbling in javascriptjs dom bubblingevent bubbling javascript examplejs get all children of in bubble phaseevent propagation in js js event bubbleis capture phase faster for domwhy event bubbling occursevent bubbling meansget event bubble javascriptwhat is the use of event bubbling in javascriptwhat is click event bubblingevent bubbling and event capturing exampleshtml click propagationcapture event javascriptbubbling event handlerchange dom during the event propagationjavascript spa event bubblingjavascript bubbling functionevent propagationjavascript event delegation and bubblingbubbling in javascriptjs capturing phasehow to capture result of an event javascriptaddeventlistener change bubbling orderwhat is bubbling and capturing in javascriptwhat is the event bubbleevent bubbling meaningmdn event bubblingwhat is web event bubblinghow to prevent parent elements from listeners getting triggered on any action on its child elementswhat is an event bubbling in javascript 3fwhat are the three phases of event propagationbubbling and capturing jswhat is event bubbling in javascript banglajs bubble buttons upjavascript click event button event bubblingexplain event bubbling in javascriptjs event phasesjvascript event bubbling vsevent bubble event bubbling or event capturingare html click event bubblingstop bubbling jswhat is event bubbling in jswhat is event bubbler in javascriptbubble click event to parentwhat is bubbling phase in javascriptevent bubbling in javascriptallow propagation javascriptevent bubbling for loop and eventevent bubbling demo in javascriptwhat is the event bubble 3f 28capturing or in the bubbling phase js click event bubble listuse of event bubling and capturingjavascript click event bubble to parentevents that not bubble upevent listener bubblingfix document bubbling in javascriptjs scroll bubblinghow to make click even bubble to parentoverwrite capture and bubble phaseswhat is event bubblehow to handle event bubbling in javascriptevent bubbling domevent bublingevent bubbling javascript truewhat is event bubblingphases of event propagation 3fcapture phase vs bubble phasehow to add event bubbling 2fpropogationevent target bubblingjs event bubbling with checkjs event bubbling nedirevent bubbling in jswrite a java script to demonstrate the event bubblingjavascript bubble up event idbubbling htmlwhat is event bubble in jsbubbling events javascripthow to propagate event in javascriptbubbling in node jsevent bubbling jswhy use events bubblingenable javascript bubblingwhat is capturing and bubbling phaseevent babblingevent bubble mdnjavascript event bubblignelement who captured the eventjavascript element bubblesjavascript how to bubble eventjs get every event on bubble upbubbling event in javascriptevent bubbling en javascriptjs detect child in bubble phaseevent handling and event bubbling in javascriptevent bubbling oopcapturing vs bubbling phase jsevent bubbling javascript w3schoolsevent bubbling in javascript w3schoolsevent bubble capturehow to prevent bubbling in javascriptjs create a bubbling buttonwhy event bubbling in javascriptwhat is event bubbling 3fnested event listeners javascriptdefine event bubblingevent bubbling example in javascript addeventlistenerbubbling and capturing in jswhat is a bubbling eventwhat is event capturing javascriptjs target for bubblingevent bubbling w3schoolswhat is an event bubble in javascript 3fevent bubbling mdnwhat is an event bubbling 3fjavascript propogation 2c bubbling 2c capturingcapture any link that is clicked in a child element htmlbubble events javascriptevent bubbling event listenerhow to identify event bubbling in pagehow to bubble event javascriptwhat does even bubbling do in jswhat is event bubbling javascriptwhat is event bubbling and delegation in javascriptevent bubbling and capturing in javascriptecent bubbling jsevent bubbling 2c capturehow do you do event bubbling 3fevent bubbling and delegation in javascriptjavascript event bubblejs stop bubblinghow set online eventhandler capturingbubbling phase javascriptbubble event in javascriptjavascript event bubbling exampleevent bubbling examplebubble events in javascriptbubbling javascript eventjs event bubblingallow event bubbling parent divevent bubbling vs parent element in javascriptbubble an capturehtml js bubblingevent bubbling and capturingcamputring phase and bubling phasewhat is an event bubbling in javascriptevent bubbling javascriptwhat is event bubbling in javascript w3schoolsjavascript dom event bubblingstop bubbling javascriptelem addeventlistener 28 27click 27 2c myfunc 2c true 29 3bevent babbling java scriptevent bubbling javascript mdnbubbling event javascriptevent capturingwhat is javascript function bubblingjavascript event bubbling orderbubbling js eventjs 2bwhat is event bubblingw3schools bubbling eventbubbling eventbubbling vent javascriptdescribe event bubbling event bubble in javascriptevent bubbling and delegationevent bubble in jshow to keep a page from bubbling javascriptbubbling javascriptevent bubbling in js in simple tremwhat is event bubbling in javascript with examplewindow add click event triggers child as welljavascript bubble eventevent bubbling in javascript mdnwhat is bubbling in dombubble event capture eventbubbling and capturing in javascriptwhat is bubbling in javascriptbubblin in jsfootablet h click bublingevent bubbling and event capturingjavascript hevent bubblingcapturing htmlevent bubbling example in javascriptjs events bubblingunderstanding javascript event bubbling mdnwhere use event bubbling in javascriptbubble in events javascriptwhat to learn before event bubblingwhat is bubbling javascriptdoes all event bubblingbubbling in javascript exampleevent looping and event bubbling in jswhat is event bubbllingcapturing vs bubbling phaseevent loop and event bubbling in javascriptbubble javascriptw3 js event bubbling and capturingjavascript event bubbling and capturingevents bubbling javascript and when to use event bubblinghtml event bubblingbubbling js testhtml bubblingwhat is the event bubble in javascriptjs bubble eventbubble event javascriptevent bubbling javascript w3addeventlistener with bubblebubbling event imagejavascript event bubblingwhat is event bubbling 2fpropagation in javascriptwhat is bubbling in jsevent capturing phase javascriptjavascript event bubble check ifjavascript bubbling eventsbubble up eventswhat is event bublingque es el event bubbling javascriptwhat javascript event bubbleexample of event bubblingevent bubbling definitionhow to stop event bubbling in javascriptclick event listener bubblingjs bubblingwhat is event bubbling in javascript with example