I wanted to make the number of clicks stored in the localStorage, and when I returned the number of clicks I would continue where I left off. I have tried doing so, but in alert
only shows NaN
:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script></head><body><scripttype="text/javascript">
var p = document.createElement("p");
document.body.appendChild(p);
$(document).ready(function(){
var cout = localStorage.getItem('cout') || 0;
$("#btnCount").click(function(){
cout = parseInt(cout)+1;
$('p').html(cout);
alert(cout);
localStorage.setItem('cout',cout);
});
});
</script>
<button type="button" id="btnCount">Click me</button>
</body>
</html>