-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path007.html
47 lines (40 loc) · 1.12 KB
/
007.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
<!DOCTYPE html>
<html>
<head>
<style>
div {
background-color: coral;
border: 1px solid;
padding: 50px;
}
p {
border-color: black;
border: 1px solid;
}
</style>
</head>
<body>
<h2>This example demonstrates the difference between bubbling and capturing when adding event listeners.</h2>
<div id="myDiv">
<p id="myP">Click this paragraph, I am Bubbling.</p>
</div>
<br>
<div id="myDiv2">
<p id="myP2">Click this paragraph, I am Capturing.</p>
</div>
<script>
document.getElementById("myP").addEventListener("click", function() {
alert("You clicked the P element!");
}, false);
document.getElementById("myDiv").addEventListener("click", function() {
alert("You clicked the DIV element!");
}, false);
document.getElementById("myP2").addEventListener("click", function() {
alert("You clicked the P element!");
}, true);
document.getElementById("myDiv2").addEventListener("click", function() {
alert("You clicked the DIV element!");
}, true);
</script>
</body>
</html>