Skip to content

Instantly share code, notes, and snippets.

@devbyray
Forked from rsschouwenaar/dark-mode-switcher.js
Created August 25, 2020 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devbyray/b9fb713083ffe4efed26b1c36a26b62a to your computer and use it in GitHub Desktop.
Save devbyray/b9fb713083ffe4efed26b1c36a26b62a to your computer and use it in GitHub Desktop.
const button = document.querySelector(".color-switch");
button.addEventListener("click", function() {
const body = document.querySelector("body");
body.classList.toggle("darkmode");
if (button) {
button.innerText = body.classList.contains("lightmode") ? "Dark" : "Light";
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment