-
Notifications
You must be signed in to change notification settings - Fork 0
/
event-listeners.html
48 lines (35 loc) · 1.17 KB
/
event-listeners.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
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript addEventListener()</h2>
<p>This example uses the addEventListener() method to add two click events to the same button.</p>
<div id="parent">
<button id="myBtn">Try it</button>
</div>
<script>
// var p = document.getElementById("parent");
// p.addEventListener("click", parentFunction, true);
var x = document.getElementById("myBtn");
x.addEventListener("click", buttonFunction1);
x.addEventListener("click", buttonFunction2, true);
x.addEventListener("click", buttonFunction3, true);
x.addEventListener("click", buttonFunction4);
function buttonFunction1(event) {
alert("Hello World 1!");
}
function buttonFunction2() {
alert("Hello World 2!");
event.stopPropagation();
}
function buttonFunction3() {
alert("Hello World 3!");
}
function buttonFunction4() {
alert("Hello World 4!");
}
function parentFunction(event) {
alert("This function on the parent was executed!");
}
</script>
</body>
</html>