Skip to content

Commit 79a4909

Browse files
committed
Add '08_bcg-changer/' from commit '745b530bae131f1662fa1a56ba350b582156b6c3'
git-subtree-dir: 08_bcg-changer git-subtree-mainline: a715146 git-subtree-split: 745b530
2 parents a715146 + 745b530 commit 79a4909

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

08_bcg-changer/index.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Javascript Color Changer</title>
7+
<link rel="stylesheet" href="style.css">
8+
</head>
9+
<body>
10+
<div id="container">
11+
<h2 id="heading">Background Color Changer</h2>
12+
13+
<button class="button" id="red"></button>
14+
<button class="button" id="green"></button>
15+
<button class="button" id="blue"></button>
16+
<button class="button" id="yellow"></button>
17+
<button class="button" id="black"></button>
18+
19+
<h3 id="hint">Click on above box to change background color</h3>
20+
21+
<button id="reset">Reset</button>
22+
</div>
23+
24+
<script src="script.js"></script>
25+
</body>
26+
</html>

08_bcg-changer/script.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const buttons = document.querySelectorAll('button');
2+
const body = document.querySelector('body');
3+
4+
5+
buttons.forEach(function (button){
6+
button.addEventListener('click', function(e){
7+
if (e.target.id === 'red') {
8+
body.style.backgroundColor = e.target.id;
9+
}
10+
if (e.target.id === 'green') {
11+
body.style.backgroundColor = e.target.id;
12+
}
13+
if (e.target.id === 'blue') {
14+
body.style.backgroundColor = e.target.id;
15+
}
16+
if (e.target.id === 'yellow') {
17+
body.style.backgroundColor = e.target.id;
18+
}
19+
if (e.target.id === 'black') {
20+
body.style.backgroundColor = e.target.id;
21+
}
22+
23+
});
24+
});
25+
26+
const resetBtn = document.getElementById('reset');
27+
resetBtn.addEventListener('click', function(e){
28+
body.style.backgroundColor = "#23282D";
29+
});
30+
31+
32+

08_bcg-changer/style.css

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
body {
2+
display: flex;
3+
justify-content: center;
4+
background-color: #23282D;
5+
color: #fff;
6+
}
7+
#container {
8+
margin-top: 20vh;
9+
10+
}
11+
.button {
12+
height: 60px;
13+
width: 60px;
14+
}
15+
#red {
16+
background-color: red;
17+
}
18+
#green {
19+
background-color: green;
20+
}
21+
#blue {
22+
background-color: blue;
23+
}
24+
#yellow {
25+
background-color: yellow;
26+
}
27+
#black {
28+
background-color: black;
29+
}
30+
#heading {
31+
font-family:'Segoe UI', Tahoma, Verdana;
32+
font-size: 25px;
33+
}
34+
#hint {
35+
font-size: medium;
36+
}
37+
#reset {
38+
height: 30px;
39+
width: 90px;
40+
41+
}

0 commit comments

Comments
 (0)