JSFiddle - React, Tailwind, and code Playground

by Juan Marco

HTML

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>store clicks in localStorage!</title>
</head>

<body>
  <p>Number of clicks on the button<input type="text" id="write" value="0"></p>
  <button id="btn-store">Increment and Save</button>
  <button id="btn-clear">Clear Storage</button>
  <script>
  var buttonStore = document.getElementById("btn-store");
  buttonStore.onclick = function() {
    var x = parseInt(localStorage.getItem("nrc"));
    if (!isNaN(x)) {
      localStorage.setItem("nrc", x + 1);
    } else {
      localStorage.setItem("nrc", "1");
    }
    document.getElementById("write").value = localStorage.getItem("nrc");
  }

  document.getElementById("write").value = localStorage.getItem("nrc");


  var buttonClear = document.getElementById("btn-clear");

  buttonClear.onclick = function() {
    console.log('clearing storage!');
    localStorage.removeItem("nrc");
    document.getElementById("write").value = '0';
  }
  </script>
</body>

</html>