Repository navigation
Expand file tree
/
Copy path01_background_changer.html
More file actions
64 lines (58 loc) · 1.76 KB
/
Copy path01_background_changer.html
File metadata and controls
64 lines (58 loc) · 1.76 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BackGround Changer</title>
<style>
span{
display:inline-block;
height: 100px;
width: 100px;
border-style: solid;
border-color: black;
border-width: 2px;
margin: 25px 50px 75px;
}
#yellow{
background-color:yellow;
}
#greenyellow{
background-color:greenyellow;
}
#grey{
background-color:grey;
}
#white{
background-color:white;
}
</style>
</head>
<body>
<div>Click The Boxes To Change The Background Color</div>
<div class="bg-buttons">
<span class="button" id="yellow"></span>
<span class="button" id="greenyellow"></span>
<span class="button" id="grey"></span>
<span class="button" id="white"></span>
</div>
<script>
let buttons = document.querySelectorAll('.button');
console.log(buttons);
buttons.forEach((item)=>{
item.addEventListener("click",(e)=>{
console.log(e.target.id);
if(e.target.id === "yellow"){
document.body.style.backgroundColor = e.target.id;
}else if(e.target.id === "greenyellow"){
document.body.style.backgroundColor = e.target.id;
}else if(e.target.id === "grey"){
document.body.style.backgroundColor = e.target.id;
}else{
document.body.style.backgroundColor = e.target.id;
}
});
});
</script>
</body>
</html>