Skip to content

Instantly share code, notes, and snippets.

@devbyray
Forked from rsschouwenaar/dark-mode-switcher.ts
Last active 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/afba5ac1a7d6548132491910049b0b50 to your computer and use it in GitHub Desktop.
Save devbyray/afba5ac1a7d6548132491910049b0b50 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("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