Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<script src="https://code.jquery.com/jquery-2.1.4.js"></script><a href="javascript:void(0)" class="bar-toggle">toggle and save state</a>
<div id="container">
</div>
 
#container {
   background-color: #ededed;
    height: 200px;
    width: 200px;
}
.with_toggle {
   background-color: #aeaeae !important;
}
 
 //retrieve current state
 $('#container').toggleClass(localStorage.toggled);
    /* Toggle */
    $('.bar-toggle').on('click',function(){
       //localstorage values are always strings (no booleans)  
       if (localStorage.toggled != "with_toggle" ) {
          $('#container').toggleClass("with_toggle", true );
          localStorage.toggled = "with_toggle";
       } else {
          $('#container').toggleClass("with_toggle", false );
          localStorage.toggled = "";
       }
    });
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers