-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbgcolors.html
42 lines (38 loc) · 912 Bytes
/
bgcolors.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
<!DOCTYPE html>
<html>
<head>
<title>
Script
</title>
<style>
body {
margin: auto 0;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
button.in {
outline: none;
border: none;
width: 250px;
height: 100px;
}
</style>
</head>
<body>
<button type="button" class="in">Change color</button>
<script>
var colors = ['blue', 'green', 'tomato', 'yellow', 'purple'],
i = 1;
var elementToChange = document.body;
var x = document.querySelector(".in");
x.addEventListener('click', function () {
elementToChange.style.backgroundColor = colors[i++];
if (i === colors.length) {
i = 0;
}
});
</script>
</body>
</html>