forked from apu52/Travel_Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Theme.js
29 lines (23 loc) · 1005 Bytes
/
Theme.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
// const themebtn = document.getElementById("toggle");
// themebtn.onclick = () => {
// document.body.classList.toggle("dark-theme");
// if (document.body.classList.contains("dark-theme")) {
// themebtn.innerHTML = '<i class="fa fa-sun-o" aria-hidden="true"></i>';
// console.log("Dark theme");
// } else {
// themebtn.innerHTML = '<i class="fa fa-moon-o" aria-hidden="true"></i>';
// console.log("Light theme");
// }
// };
const themeToggle = document.getElementById("themeToggle");
const themeLabel = document.querySelector(".toggle-label");
themeToggle.addEventListener("change", () => {
document.body.classList.toggle("dark-theme");
if (document.body.classList.contains("dark-theme")) {
themeLabel.style.background = "#fff"; // Adjust color for the checked state as needed
console.log("Dark theme");
} else {
themeLabel.style.background = "var(--primary-color)"; // Adjust color for the unchecked state as needed
console.log("Light theme");
}
});