-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
30 lines (25 loc) · 845 Bytes
/
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
let color1 = document.getElementById('color1');
let color2 = document.getElementById('color2');
let color3 = document.getElementById('color3');
let color4 = document.getElementById('color4');
// ==== FUNCTION TO CHANGE BACKGROUND COLOR ====
function changeBG(color){
document.body.style.backgroundColor = color;
}
// ==== ADDING CLICK EVENT LISTENER TO EACH COLOR ====
// COLOR 1
color1.addEventListener('click', function(){
changeBG(getComputedStyle(color1).backgroundColor);
} );
// COLOR 2
color2.addEventListener('click', function(){
changeBG(getComputedStyle(color2).backgroundColor);
} );
// COLOR 3
color3.addEventListener('click', function(){
changeBG(getComputedStyle(color3).backgroundColor);
} );
// COLOR 4
color4.addEventListener('click', function(){
changeBG(getComputedStyle(color4).backgroundColor);
} );