STANAANDREY

session storage cnt

Nov 11th, 2021 (edited)
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.61 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5.   <meta charset="UTF-8">
  6.   <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8.   <title>Document</title>
  9. </head>
  10.  
  11. <body>
  12.   <button onclick="handleClick()">+1</button>
  13.   <i>0</i>
  14. </body>
  15. <script>
  16.   console.log('hi');
  17.   const ielem = document.querySelector('i');
  18.   if (!sessionStorage.cnt) {
  19.     sessionStorage.cnt = new Number(0);
  20.   }
  21.  
  22.   ielem.innerText = sessionStorage.cnt;
  23.   function handleClick() {
  24.     ielem.innerText = String(++sessionStorage.cnt);
  25.   }
  26.  
  27. </script>
  28.  
  29. </html>
Add Comment
Please, Sign In to add comment