forked from bethrobson/Head-First-JavaScript-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevents.html
More file actions
37 lines (35 loc) · 680 Bytes
/
events.html
File metadata and controls
37 lines (35 loc) · 680 Bytes
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title> Handling events in IE8 and earlier </title>
<style>
span {
cursor: pointer;
}
</style>
<script>
window.onload = function() {
var div = document.getElementById("clickme");
if (div.addEventListener) {
div.addEventListener("click", handleClick, false);
} else if (div.attachEvent) {
div.attachEvent("click", handleClick);
}
};
function handleClick(e) {
var evt = e || window.event;
var target;
if (evt.target) {
target = evt.target;
} else {
target = evt.srcElement;
}
alert("You clicked on " + target.id);
}
</script>
</head>
<body>
<span id="clickme">Click me!</span>
</body>
</html>