I have a checkboxes that are being stored in a cookie.
Here is the jquery code:
//JQuery that will set the checkbox in it's current state
$("#checkAll").on("change", function() {
$(':checkbox').not(this).prop('checked', this.checked);
});
$(":checkbox").on("change", function(){
var checkboxValues = {};
$(":checkbox").each(function(){
checkboxValues[this.id] = this.checked;
});
$.cookie('checkboxValues', checkboxValues, { expires: 7, path: '/' })
});
function repopulateCheckboxes(){
var checkboxValues = $.cookie('checkboxValues');
if(checkboxValues){
Object.keys(checkboxValues).forEach(function(element) {
var checked = checkboxValues[element];
$("#" + element).prop('checked', checked);
});
}
}
$.cookie.json = true;
repopulateCheckboxes();
The code above works perfectly but when I try to use a button to uncheck them it does not uncheck at all.
Here is the function that I used:
$("#UncheckAll").click(function(){
$("input[type='checkbox']").prop('checked',false);
});
What should I do? could somebody help me.