-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
43 lines (35 loc) · 1.53 KB
/
app.js
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
const buttons = document.querySelectorAll(".button");
const body = document.querySelector("body");
const nav = document.querySelector("nav"); // Add this to target the nav
const contact = document.querySelector(".contact"); // Add this to target the contact
buttons.forEach(function (button) {
button.addEventListener('click', function(change) {
console.log(change.target.id);
// Change the background color of the body
if (change.target.id === 'grey') {
body.style.backgroundColor = change.target.id;
}
if (change.target.id === 'white') {
body.style.backgroundColor = change.target.id;
}
if (change.target.id === 'blue') {
body.style.backgroundColor = change.target.id;
}
if (change.target.id === 'yellow') {
body.style.backgroundColor = change.target.id;
}
nav.style.backgroundColor = 'transparent';
contact.style.backgroundColor = 'transparent';
});
});
////////////shorter version of these code////////////
// const buttons = document.querySelectorAll(".button");
// const body = document.querySelector("body");
// const nav = document.querySelector("nav");
// const contact = document.querySelector(".contact");
// buttons.forEach(function (button) {
// button.addEventListener('click', function(change) {
// const newColor = change.target.id; // Get the selected color
// body.style.backgroundColor = newColor; // Change the body background color
// });
// });