I am trying to create a button that will clear the local storage for a user using localStorage.clear();
, but it is not working as expected.
Unfortunately, if you check out the demo, you'll see that it doesn't work properly.
JS code:
var money = 0;
//localStorage function
if(localStorage.money) money = localStorage.getItem('money');
document.getElementById("money").innerHTML = money;
//Clicking function
function moneyClick(number){
money = parseInt(money) + 10;
document.getElementById ("money").innerHTML = money;
localStorage.setItem('money', money);
}
//Clear data function
function clearClick(number){
localStorage.clear();
}