-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
36 lines (28 loc) · 1013 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
31
32
33
34
35
36
var red = document.querySelector(".red");
var cyan = document.querySelector(".cyan");
var violet = document.querySelector(".violet");
var orange = document.querySelector(".orange");
var pink = document.querySelector(".pink");
const center = document.querySelector(".center");
// console.log(window.getComputedStyle(red).backgroundColor) ;
const getBGColor = (SelectedElement) => {
return window.getComputedStyle(SelectedElement).backgroundColor;
};
// console.log(getBGColor(red)) ;
// console.log(getBGColor(pink)) ;
// console.log(getBGColor(orange)) ;
// console.log(getBGColor(cyan)) ;
// pink.addEventListener('mousecenter', () => {
// center.style.background = color;
// });
const magicColorChanger = (element) => {
var color = getBGColor(element);
return element.addEventListener('click', () => {
center.style.background = color;
});
};
magicColorChanger(red) ;
magicColorChanger(cyan) ;
magicColorChanger(violet) ;
magicColorChanger(pink) ;
magicColorChanger(orange) ;