-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventbubbling html2 code.html
76 lines (63 loc) · 2.02 KB
/
eventbubbling html2 code.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Event Bubbling</title>
<style>
.child{
background-color: aliceblue;
border: 2px solid black;
padding: 14px;
margin: 14px;
cursor: pointer;
}
.childContainer{
background-color: beige;
padding: 14px;
margin: 14px;
}
.container{
background-color: rgb(227, 227, 28);
padding: 14px;
margin: 14px;
}
</style>
</head>
<body>
<div class="container">
<section class="childContainer">
<div class="child">
I am a child
</div>
</section>
</div>
<script>
document.querySelector(".child").addEventListener("contextmenu", (e) => {
e.stopPropagation()
alert("Child Was clicked")
})
document.querySelector(".childContainer").addEventListener("contextmenu", (e) => {
e.stopPropagation()
alert("childContainer Was clicked")
})
document.querySelector(".container").addEventListener("click", (e) => {
alert("container Was clicked")
})
function getRandomColor(){
let val1 = Math.ceil(0 + Math.random() * 255);
let val2 = Math.ceil(0 + Math.random() * 255);
let val3 = Math.ceil(0 + Math.random() * 255);
return `rgb(${val1}, ${val2}, ${val3})`
}
// let a = setInterval(() =>{
// Document.querySelector(".childContainer").style.background = getRandomColor()
// }, 1000);
// console.log(a)
let a = setTimeout(() =>{
Document.querySelector(".childContainer").style.background = getRandomColor()
}, 5000);
console.log(a)
</script>
</body>
</html>