Skip to content

Instantly share code, notes, and snippets.

@sayham-sjb
Last active January 25, 2018 18:13
Show Gist options
  • Save sayham-sjb/93819f3598a82c4a1c6f8d173e190550 to your computer and use it in GitHub Desktop.
Save sayham-sjb/93819f3598a82c4a1c6f8d173e190550 to your computer and use it in GitHub Desktop.
ClickCountWithJavaScript_localStorage #js #VS
$("#countButton").on('click', function(e) {
if (typeof(Storage) !== "undefined") {
if (localStorage.clickcount) {
localStorage.clickcount = parseInt($("#displayCount").text());
localStorage.clickcount = Number(localStorage.clickcount) + 1;
} else {
localStorage.clickcount = 0;
}
document.getElementById("displayCount").innerHTML = localStorage.clickcount;
} else {
document.getElementById("displayCount").innerHTML = 0;
}
});
$("#resetButton").on('click', function(e) {
localStorage.clickcount = 0;
document.getElementById("displayCount").innerHTML = localStorage.clickcount;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment