mirror of
https://github.com/its-michaelroy/Simple_Portfolio.git
synced 2026-06-03 23:00:43 +00:00
20 lines
574 B
JavaScript
20 lines
574 B
JavaScript
document.addEventListener("DOMContentLoaded", function () {
|
|
const body = document.body;
|
|
const themeToggle = document.getElementById("theme-toggle");
|
|
|
|
themeToggle.addEventListener("click", function () {
|
|
body.classList.toggle("dark-mode");
|
|
toggleThemeIcon();
|
|
});
|
|
|
|
function toggleThemeIcon() {
|
|
if (body.classList.contains("dark-mode")) {
|
|
themeToggle.innerHTML = '<i class="fas fa-sun"></i>';
|
|
} else {
|
|
themeToggle.innerHTML = '<i class="fas fa-moon"></i>';
|
|
}
|
|
}
|
|
|
|
toggleThemeIcon(); // Set initial icon based on the current theme
|
|
});
|