Skip to content

Instantly share code, notes, and snippets.

@rsschouwenaar
Created May 1, 2020 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rsschouwenaar/771b2016a24e333b07d01ff9b79586fe to your computer and use it in GitHub Desktop.
Save rsschouwenaar/771b2016a24e333b07d01ff9b79586fe to your computer and use it in GitHub Desktop.
const button: HTMLButtonElement = document.querySelector(".color-switch");
button.addEventListener("click", function() {
const body: HTMLBodyElement = document.querySelector("body");
body.classList.toggle("lightmode");
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