Local Storage mostrar div e esconder

by thvinic

HTML

<div id="container">
    <a id="foo" href="javascript:void(0);">Click Me</a>
    <div id="bar"></div>
</div>

CSS

#container {
    width:200px;
    height:220px;
}
#foo {
    display:block;
    float:left;
    width:200px;
    height:20px;
    text-align:center;
}
#bar {
    display:none;
    float:left;
    height:200px;
    width:200px;
    background:#000000;
}

JavaScript

$(document).ready(function () {
    $('#foo').click(function () {
        $(this).siblings().toggle();
        //you need to pass string values, your variables display & block was not defined
        localStorage.setItem('display', $(this).siblings().is(':visible'));
    });
    var block = localStorage.getItem('display');
    if (block == 'true') {
        $('#bar').show()
    }
});