I want to do this :
- When I click the checkbox "div=true"
or "div=flase"
, will be shown or hidden
- Status of checkbox
to be saved and with this, even the last method called to be saved
Problem
- Status of checkbox
is saved at refresh of page, but the last method called is not saved.
I do not understand where is my mistake.
Here is the code:
<input type='checkbox' id='LineOp' /> Show/Hide Weekends
<div id="true">
<p>Hide weekend</p>
</div>
<div id="false">
<p>Show weekend</p>
</div>
function SaveLastCheck() {
var getStstus = localStorage.getItem("LineOp");
if (getStstus === "true")
$("#LineOp").prop("checked", true);
$("#LineOp").click(function(){
localStorage.setItem('LineOp', $(this).prop("checked"));
});
}
$(document).ready(function() {
SaveLastCheck();
});
$(document).ready(function show_weekends () {
var checkbox = $('#LineOp');
var dependent = $('#true');
if (checkbox.attr('checked') !== undefined){
dependent.show();
} else {
dependent.hide();
}
checkbox.change(function(e){
dependent.toggle();
});
});
$(document).ready(function hide_weekends () {
var checkbox = $('#LineOp');
var dependent = $('#false');
if (checkbox.attr('checked') == undefined){
dependent.show();
} else {
dependent.hide();
}
checkbox.change(function(e){
dependent.toggle();
});
});
HERE IS MY EXAMPLE http://jsfiddle.net/b3g6arbd/4/