I'm working on local storage using jQuery. I've got an input field in which you can type some text, press enter, refresh and the text is still there. So that's working fine.
But I want to combine it with a different function I wrote. In this function a user can click on a grey button which will then "activate" it so it turns red, and it will add a 1 to the container. It's a "like button".
So how can I save the click counter information (button turning red, and value updated) using local storage?
I made this jsfiddle: http://jsfiddle.net/Yazuri/7ZxMK/
jQuery(function ($) {
if (typeof (window.localStorage) != "undefined") {
$("input[type=text]").val(function () {
return localStorage.getItem(this.id);
});
$("input[type=text]").on("change", function () {
localStorage.setItem(this.id, $(this).val());
});
}
});