-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.html
More file actions
33 lines (28 loc) · 1.03 KB
/
storage.html
File metadata and controls
33 lines (28 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!DOCTYPE html>
<html>
<head>
<script>
// Set starting value of counter to 0
if (!localStorage.getItem('counter'))
localStorage.setItem('counter', 0);
// Load current value of counter
document.addEventListener('DOMContentLoaded', () => {
document.querySelector('#counter').innerHTML = localStorage.getItem('counter');
// Count every time button is clicked
document.querySelector('button').onclick = () => {
// Increment current counter
let counter = localStorage.getItem('counter');
counter++;
// Update counter
document.querySelector('#counter').innerHTML = counter;
localStorage.setItem('counter', counter);
}
});
</script>
<title>My Website</title>
</head>
<body>
<h1 id="counter"></h1>
<button>Click Here!</button>
</body>
</html>