forked from bethrobson/Head-First-JavaScript-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
listener.html
40 lines (37 loc) · 879 Bytes
/
listener.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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title> Handling events in with addEventListener </title>
<style>
span {
cursor: pointer;
}
</style>
<script>
window.addEventListener("load", init, false);
function init() {
var div = document.getElementById("clickme");
div.addEventListener("click", handleClick, false);
}
function handleClick(e) {
var target = e.target;;
alert("You clicked on " + target.id);
target.removeEventListener("click", handleClick, false);
}
/*
window.onload = function() {
var div = document.getElementById("clickme");
div.addEventListener("click", handleClick, false);
div.addEventListener("click", handleClickAgain, false);
};
function handleClickAgain() {
alert("Another click handler just executed!");
}
*/
</script>
</head>
<body>
<span id="clickme">Click me!</span>
</body>
</html>