-
Notifications
You must be signed in to change notification settings - Fork 425
/
aboutdarkmode.js
39 lines (36 loc) · 1 KB
/
aboutdarkmode.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
let buttonText = document.getElementById("darkmode-button");
let theme = localStorage.getItem("theme");
// let theme=localStorage.getItem('theme');
let para = document.getElementById("para");
let h1 = document.querySelector("h1");
console.log(para.innerText);
var bodyelem = document.body;
function darkmode() {
localStorage.setItem("theme", "darkmode");
let val = localStorage.getItem("theme");
// bodyelem=document.body;
bodyelem.classList.add(val);
para.style.color = "white";
h1.style.color = "white";
}
function lightmode() {
//let bodyelem=document.body;
localStorage.setItem("theme", "");
let val = localStorage.getItem("theme");
bodyelem.classList.value = val;
para.style.color = "black";
h1.style.color = "black";
// localStorage.setItem('theme','');
}
if (theme == "darkmode") {
darkmode();
}
buttonText.addEventListener("click", () => {
theme = localStorage.getItem("theme");
console.log(theme);
if (theme === "darkmode") {
lightmode();
} else {
darkmode();
}
});