-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (30 loc) · 984 Bytes
/
index.js
File metadata and controls
32 lines (30 loc) · 984 Bytes
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
const checkbox = document.getElementById('checkbox');
const body = document.getElementById('body');
const switchh = document.querySelector('.switch');
checkbox.addEventListener('click', thememode)
window.onload=()=>{
let theme = localStorage.getItem('theme');
if(theme === 'light-mode'){
var element = document.body;
element.classList.remove("dark-mode");
localStorage.setItem('theme','light-mode');
}
else{
var element = document.body;
element.classList.add("dark-mode");
localStorage.setItem('theme','dark-mode');
}
}
function thememode() {
let theme = localStorage.getItem('theme');
if(theme === 'light-mode'){
var element = document.body;
element.classList.add("dark-mode");
localStorage.setItem('theme','dark-mode');
}
else{
var element = document.body;
element.classList.remove("dark-mode");
localStorage.setItem('theme','light-mode');
}
}