JSFiddle - React, Tailwind, and code Playground

by techiedelight

HTML

<div id="container" class="light"></div>
<button id="darkmode">Dark Mode</button>
<button id="lightmode">Light Mode</button>

CSS

div {
  width: 500px;
  height: 300px;
  border: 1px solid black;
}

button {
  margin: 10px;
}

.light {
  background-color: #ffffff;
}

.dark {
  background-color: #243447;
}

JavaScript

function replaceClass(id, oldClass, newClass) {
  var elem = document.getElementById(id);
  elem.classList.remove(oldClass);
  elem.classList.add(newClass);
}

document.getElementById("darkmode").onclick = function() {
  replaceClass("container", "light", "dark");
}

document.getElementById("lightmode").onclick = function() {
  replaceClass("container", "dark", "light");
}