-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBubbling.html
69 lines (64 loc) · 1.41 KB
/
Bubbling.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<style>
#myDiv1,
#myDiv2 {
background-color: coral;
padding: 50px;
}
#myP1,
#myP2 {
background-color: aliceblue;
font-size: 20px;
border: 1px solid;
padding: 20px;
}
</style>
<body>
<h2>javascript addEventListener()</h2>
<div id="myDiv1">
<h2>Bubbling:</h2>
<p id="myP1">Click me!</p>
</div>
<br />
<div id="myDiv2">
<h2>Capturing:</h2>
<p id="myP2">Click me!</p>
</div>
<script>
document.getElementById("myP1").addEventListener(
"click",
function () {
alert("you clicked the white element!");
},
false
);
document.getElementById("myDiv1").addEventListener(
"click",
function () {
alert("you clicked the orange element");
},
false
);
document.getElementById("myP2").addEventListener(
"click",
function () {
alert("you clicked the white elemet");
},
true
);
document.getElementById("myDiv2").addEventListener(
"click",
function () {
alert("you clicked the orange element");
},
true
);
</script>
</body>
</html>