-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11_Theme_Change_Button.js
More file actions
46 lines (36 loc) · 1.02 KB
/
Copy path11_Theme_Change_Button.js
File metadata and controls
46 lines (36 loc) · 1.02 KB
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
const but_1=document.querySelector(".button1");
let curr_Theme="Light_Theme";
// 1st Approach
// Only One Approach will work At a Time
let body = document.querySelector("body");
but_1.onclick = () => {
if(curr_Theme!="Dark_Theme"){
body.style.backgroundColor="Black";
body.style.color="White";
curr_Theme="Dark_Theme";
console.log(curr_Theme);
}
else{
body.style.backgroundColor="White";
body.style.color="Black";
curr_Theme="Light_Theme";
console.log(curr_Theme);
}
}
// 2nd Approach
const but_2=document.querySelector(".button2");
body = document.querySelector("body");
but_2.onclick = () => {
if(curr_Theme!="Red_Theme"){
body.classList.add("Red_Theme");
body.classList.remove("Green_Theme");
curr_Theme="Red_Theme";
console.log(curr_Theme);
}
else{
body.classList.add("Green_Theme");
body.classList.remove("Red_Theme");
curr_Theme="Green_Theme";
console.log(curr_Theme);
}
}