JSFiddle - React, Tailwind, and code Playground
by Sergei Sokolov
HTML
<div id="test"></div>
<button class="button">переключить</button>
CSS
#test {
width:100px;height:100px;
background-color:green;
}
.boxed {
border:3px solid purple;
background-color:yellow !important;
}
JavaScript
$(document).ready(function(){
var key = "__body_boxed__";
var boxedState = false;
if( localStorage && JSON.parse(localStorage.getItem(key))) {
boxedState = true;
$("#test").toggleClass("boxed");
$("#test").text("LS boxed!")
}
$(".button").click(function(){
$("#test").toggleClass("boxed");
boxedState = !boxedState;
localStorage && localStorage.setItem(key, JSON.stringify(boxedState));
return false;
});
});