-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackgroundColor.html
More file actions
68 lines (63 loc) · 1.7 KB
/
backgroundColor.html
File metadata and controls
68 lines (63 loc) · 1.7 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Background color changer</title>
<style>
body{
text-align: center;
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
}
.button{
height:200px;
width:200px;
border: 4px solid black;
border-radius: 10px;
margin:0 auto;
}
div{
display:flex;
justify-content: center;
align-items: center;
margin-top:20px;
padding: 3px;
}
#pink{
background-color: #ffc0cbf8;
}
#yellow{
background-color: #ffff00b0;
}
#green{
background-color: #008000cc;
}
#blue{
background-color: #0000ffc2;
}
</style>
</head>
<body>
<h1>Background Color Changer</h1>
<h4>Change the Color by clicking any of the box color to background color</h4>
<div>
<div class="button" id="pink"></div>
<div class="button" id="yellow"></div>
<div class="button" id="blue"></div>
<div class="button" id="green"></div>
</div>
<script>
let btn = document.querySelectorAll(".button");
let body = document.querySelector("body");
btn.forEach(function (box){
// console.log(box);
box.addEventListener("click",(e)=>{
// console.log("btn was clicked");
// console.log(e.target);
// console.log(e.target.id);
body.style.backgroundColor = e.target.id;
})
})
</script>
</body>
</html>