JSFiddle - React, Tailwind, and code Playground
HTML
<button class="theme-toggle" data-theme="default">Default</button>
<button class="theme-toggle" data-theme="dark">Dark</button>
<button class="theme-toggle" data-theme="light">Light</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
CSS
body[theme="default"] {
background-color: #ccc;
}
body[theme="dark"] {
background-color: #333;
}
body[theme="light"] {
background-color: #fff;
}
JavaScript
(function ($) {
var $body = $('body');
var loadTheme = function () {
$body.attr('theme', localStorage.getItem('theme') || 'default');
};
$('.theme-toggle').click(function () {
localStorage.setItem('theme', $(this).data('theme'));
loadTheme();
});
loadTheme();
} (jQuery));