Last active
January 25, 2018 18:13
-
-
Save sayham-sjb/93819f3598a82c4a1c6f8d173e190550 to your computer and use it in GitHub Desktop.
ClickCountWithJavaScript_localStorage #js #VS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#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