(ES6) ES6 (2016)

EventBubbling (EB01)

   1:  //<div id="outer">
   2:  //    <p id="inner">Click me!</p>
   3:  //</div>
   4:      const outerDiv = document.getElementById('outer');
   5:      const innerParagraph = document.getElementById('inner');
   6:      innerParagraph.addEventListener('click', function(event) {
   7:      console.log('Inner paragraph clicked!');
   8:      //event.stopPropagation(); // Stop bubbling (uncomment this to prevent outer div click)
   9:  });
  10:      outerDiv.addEventListener('click', function(event) {
  11:      console.log('Outer div clicked!'); //this happens only if bubbling isn't stopped
  12:  });
  13:  



When an event occurs on an HTML element, it first triggers on that specific element.
Then, unless explicitly stopped, the event "bubbles" up the DOM tree, triggering on each of the element's ancestors in turn.
This process continues until it reaches the document's root.


Inner paragraph clicked!
Outer div clicked!





EventBubbling context:






ES6 context:



Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23>  <24>  <25
Link to this page: http://www.vb-net.com/JavascriptES6/EB01.htm
<TAGS>  <ARTICLES>  <FRONT>  <CORE>  <MVC>  <ASP>  <NET>  <DATA>  <TASK>  <XML>  <KIOSK>  <NOTES>  <SQL>  <LINUX>  <MONO>  <FREEWARE>  <DOCS> <TRAVELS> <FLOWERS> <RESUME> < THANKS ME>