-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
42 lines (38 loc) · 1002 Bytes
/
index.html
File metadata and controls
42 lines (38 loc) · 1002 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
38
39
40
41
42
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
#box {
width: 200px;
height: 200px;
background-color: lightgray;
margin: 20px auto;
transition: background-color 0.5s;
}
</style>
</head>
<body>
<h1>background changer</h1>
<div id="box">
<button>Change Background</button>
</div>
<script>
const button = document.querySelector("button");
const box = document.getElementById("box");
button.addEventListener("click", () => {
box.style.backgroundColor = getRandomColor();
});
function getRandomColor() {
const letters = "0123456789ABCDEF";
let color = "#";
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
</script>
</body>
</html>