-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
62 lines (50 loc) · 1.98 KB
/
script.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const Buttons = document.querySelectorAll('.btn');
const Back = document.querySelector('.back');
const body = document.querySelector('body');
const heading = document.getElementsByTagName('h1');
const heading2 = document.getElementById('change');
// Store the original background color and text content
const originalBackgroundColor = body.style.backgroundColor;
const originalTextContent = heading.textContent;
Buttons.forEach(function (button) {
console.log(button);
button.addEventListener('click', function (e) {
console.log(e);
console.log(e.target);
if (e.target.id === 'red') {
body.style.backgroundColor = e.target.id;
heading2.textContent = "You have changed the background color to Red";
}
if (e.target.id === 'green') {
body.style.backgroundColor = e.target.id;
for (let i = 0; i < heading.length; i++) {
heading[i].style.color = 'white';
}
heading2.textContent = "You have changed the background color to Green";
for (let i = 0; i < heading.length; i++) {
heading[i].style.color = 'white';
}
}
if (e.target.id === 'yellow') {
body.style.backgroundColor = e.target.id;
heading2.textContent = "You have changed the background color to Yellow";
for (let i = 0; i < heading.length; i++) {
heading[i].style.color = 'white';
}
}
if (e.target.id === 'blue') {
body.style.backgroundColor = e.target.id;
heading2.textContent = "You have changed the background color to Blue";
for (let i = 0; i < heading.length; i++) {
heading[i].style.color = 'white';
}
}
});
Back.addEventListener('click', function (e) {
body.style.backgroundColor = 'white'; // Reverting to the original background color of the body
heading2.textContent = "You have changed the Page into its Original State";
for (let i = 0; i < heading.length; i++) {
heading[i].style.color = 'black';
}
});
});