My website has tabs and within that tab, info cards and a checkbox on the right hand side that highlights the card in a different colour. How can I makes it so that onclick the highlighting is saved even if the page is refreshed or if the page is sent as a link? Full code here: http://codepen.io/johnsonshara/pen/obGjGN (below code not in code pen version)
What I have tried:
function save () {
var fieldValue = document.getElementById('like').value;
localStorage.setItem('checkbox', 'fieldValue');
}
function load () {
var storedValue = localStorage.getItem('checkbox');
if(storedValue){
document.getElementById('like').value = storedValue;
}
}
And This:
function save() {
if(typeof(Storage) !== "undefined") {
if (localStorage.setItem) {
localStorage.setItem = document.getElementById("like");
} else {
localStorage.getItem = .hasClass.apply;
}
document.getElementById("like").innerHTML = localStorage.toString;
} else {
document.getElementById("like").innerHTML = "Sorry, an error occured.";
}
}
html
<input type="checkbox" class="faChkRnd" onclick="save()" id="like" >