-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathexercise2.html
45 lines (43 loc) · 1.12 KB
/
exercise2.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Exercise #2: Changing colors</title>
<style>
#mydiv {
width: 200px;
height: 200px;
border: 1px solid black;
}
</style>
<script>
function changeColor() {
var color = this.style.backgroundColor;
var newcolor;
switch (color) {
case "red":
newcolor = "green";
break;
case "green":
newcolor = "blue";
break;
case "blue":
newcolor = "red";
break;
default: // this should never happen
newcolor = "blue;";
}
this.style.backgroundColor = newcolor;
}
function init() {
var mydiv = document.getElementById("mydiv");
mydiv.style.backgroundColor = "blue";
mydiv.onclick = changeColor;
}
window.onload = init;
</script>
</head>
<body>
<div id="mydiv"></div>
</body>
</html>