-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
33 lines (27 loc) · 891 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
function changeMode() {
changeClasses();
changeText();
}
function changeClasses() {
button.classList.toggle(darkModeClass);
h1.classList.toggle(darkModeClass);
body.classList.toggle(darkModeClass);
footer.classList.toggle(darkModeClass);
}
function changeText() {
const lightMode = 'Light Mode';
const darkMode = 'Dark Mode';
if (body.classList.contains(darkModeClass)) {
button.innerHTML = lightMode;
h1.innerHTML = darkMode + ' ON';
return;
}
button.innerHTML = darkMode;
h1.innerHTML = lightMode + " ON";
}
const darkModeClass = 'dark-mode';
const button = document.getElementById('mode-selector');
const h1 = document.getElementById('page-title');
const body = document.getElementsByTagName('body')[0];
const footer = document.getElementsByTagName('footer')[0];
button.addEventListener('click', changeMode);