I am trying to set data on localStorage as 1/0.Then if I get 1 from it I want to checked a checkbox else unchecked.I was wrote a code but it isn't working.And I can't find-out what I am doing wrong!
<label class="a-b-c">
<input id="check-it" type="checkbox" name="check">
Check.
</label>
$(window).load(set_func_o());
function set_func_o(){
try_it();
$('#check-it').change(function(){
var chk= this.checked ? '1':'0';
localStorage.setItem('checkit-the-item',chk);
try_it();
});
function try_it(){
var check_stat= localStorage.getItem('checkit-the-item');
check_stat === '1' ? $('#checkit').prop('checked',true):$('#checkit').prop('checked',false);
}
}
Suggestion please!
()on your load binding. It should be$(window).load(set_func_o);so you are giving it a function reference, not invoking it immediately.