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