-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
128 lines (102 loc) · 3.37 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
/* div#child{
min-width: 100px;
min-height: 100px;
border: 2px solid black;
padding:43px;
background-color: yellow;
}
div#parentt{
min-width: 100px;
min-height: 100px;
border: 2px solid black;
padding:30px;
background-color: grey;
}
div#grandparent{
min-width: 100px;
min-height: 100px;
border: 2px solid black;
padding:30px;
background-color: goldenrod;
} */
/* or in simple way */
div{
min-width: 100px;
min-height: 100px;
border: 2px solid black;
padding:30px;
}
</style>
</head>
<body>
<ul id="parent">
<li class="child">one</li>
<li class="child">two</li>
<li class="child">three</li>
<li class="child">four</li>
<li class="child">five</li>
<li class="child">six</li>
<li class="child">seven</li>
</ul>
<ul id="parent1">
<li class="child1">one</li>
<li class="child1">two</li>
<li class="child1">three</li>
<li class="child1">four</li>
<li class="child1">five</li>
<li class="child1">six</li>
<li class="child1">seven</li>
</ul>
<ul onClick=parent2click(event) id="parent2">
<li onClick=child2clickk(event) class="child2">one</li>
<li onClick=child2click(event) class="child2">two</li>
<li onClick=child2click(event) class="child2">three</li>
<li onClick=child2click(event) class="child2">four</li>
<li onClick=child2click(event) class="child2">five</li>
<li onClick=child2click(event) class="child2">six</li>
<li onClick=child2click(event) class="child2">seven</li>
</ul>
<div id="grandparent">
<div id="parentt">
<div id="child"></div>
</div>
</div>
<script type="text/javascript">
//========== Event In a most obvisous way ===================
let children = Array.from(document.getElementsByClassName("child"));
for (const child of children) {
child.addEventListener('click',()=>{
console.log("clicked child", child.innerHTML, "from Obvious Way");
})
}
//========== Event In a most obvisous way ===================
//========== Event Delegation ===============================
let parent = document.getElementById('parent1');
parent.addEventListener('click',(event)=>{
console.log("clicked child", event.target.innerHTML,"from Event delegation");
})
//========== Event Delegation ===============================
//================ BUBBLING ===================
function parent2click(event){
alert("parent");
}
function child2click(event){
alert("child :Stop Propagation");
event.stopPropagation();
}
function child2clickk(event){
alert("child : DO NOT Stop Propagation");
}
//================ BUBBLING ====22===============
</script>
<script src="./script.js"></script>
</body>
</html>