-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
30 lines (26 loc) · 987 Bytes
/
main.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
const darkSwitch = document.querySelector('.dark-switch');
const lightSwitch = document.querySelector('.light-switch');
const body = document.querySelector('body');
// darkSwitch.addEventListener('click',function(e){
// body.classList.add('dark-mode');
// })
//condition for darkmode if true
if(localStorage.getItem("darkmode")){
body.classList.add("dark-mode");
darkSwitch.classList.remove('active');
lightSwitch.classList.add('active')
}
darkSwitch.addEventListener('click',()=>{
body.classList.add('dark-mode');
darkSwitch.classList.remove('active');
lightSwitch.classList.add('active');
// making it stay in darkmode even if we reflesh
localStorage.setItem("darkmode","true")
});
lightSwitch.addEventListener('click',()=>{
body.classList.remove('dark-mode');
darkSwitch.classList.add('active');
lightSwitch.classList.remove('active');
//removing it from dark mode even if we reflesh
localStorage.removeItem("darkmode");
});