I am trying to keep checkboxes checked on refresh with localStorage. All modern browsers do the job except IE11 (and lower)
Fiddle:
(function() {
var boxes = document.querySelectorAll("input[type='checkbox']");
for (var i = 0; i < boxes.length; i++) {
var box = boxes[i];
if (box.hasAttribute("store")) {
setupBox(box);
}
}
function setupBox(box) {
var storageId = box.getAttribute("store");
var oldVal = localStorage.getItem(storageId);
console.log(oldVal);
box.checked = oldVal === "true" ? true : false;
box.addEventListener("change", function() {
localStorage.setItem(storageId, this.checked);
});
}
})();
Does anyone know if there's a way to somehow adapt this to IE? Or maybe you know a script that keeps checkboxes checked on refresh in all browsers? (Doesn't matter if it's in javascript or jquery). Any help is appreciated.