File tree Expand file tree Collapse file tree 1 file changed +62
-0
lines changed
25 - Event Capture, Propagation, Bubbling and Once Expand file tree Collapse file tree 1 file changed +62
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 " />
5+ < title > Understanding JavaScript's Capture</ title >
6+ </ head >
7+ < body class ="bod ">
8+ < div class ="one ">
9+ < div class ="two ">
10+ < div class ="three "> </ div >
11+ </ div >
12+ </ div >
13+
14+ < style >
15+ html {
16+ box-sizing : border-box;
17+ }
18+
19+ * ,
20+ * : before ,
21+ * : after {
22+ box-sizing : inherit;
23+ }
24+
25+ div {
26+ width : 100% ;
27+ padding : 100px ;
28+ }
29+
30+ .one {
31+ background : thistle;
32+ }
33+
34+ .two {
35+ background : mistyrose;
36+ }
37+
38+ .three {
39+ background : coral;
40+ }
41+ </ style >
42+
43+ < button > </ button >
44+ < script >
45+ const divs = document . querySelectorAll ( "div" ) ;
46+
47+ function logText ( e ) {
48+ console . log ( this . classList . value ) ;
49+ // e.stopPropagation();
50+ }
51+
52+ document . body . addEventListener ( "click" , logText ) ;
53+
54+ divs . forEach ( ( div ) =>
55+ div . addEventListener ( "click" , logText , {
56+ capture : false ,
57+ once : true ,
58+ } )
59+ ) ;
60+ </ script >
61+ </ body >
62+ </ html >
You can’t perform that action at this time.
0 commit comments