File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ // allows select dynamic elements
2+ // event propogation - order the events are fired
3+ // event bubbling - clicked element first then bubles up --
4+ // default
5+ // event capturing - fires at the root and fires until
6+ // reaches target
7+
8+ const list_items = document . querySelector ( '.list-items' ) ;
9+ const container = document . querySelector ( '.container' ) ;
10+
11+ function showBubbling ( e ) {
12+ // output all element list-items and child like li.item
13+ console . log ( 'current target :' , e . currentTarget ) ;
14+ //output only target element clicked example: click link show only a href
15+ console . log ( 'target : ' , e . target ) ;
16+ // checked
17+ if ( e . target . classList . contains ( 'link' ) ) {
18+ console . log ( 'your clicked link' ) ;
19+ }
20+ }
21+
22+ // if link will not click here
23+ function stopPropogation ( e ) {
24+ e . stopPropogation ;
25+ console . log ( 'not click' ) ;
26+ }
27+
28+ // container.addEventListener('click', showBubbling);
29+ list_items . addEventListener ( 'click' , showBubbling ) ;
You can’t perform that action at this time.
0 commit comments