-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathlocalStorage-remember.html
More file actions
73 lines (53 loc) · 1.51 KB
/
localStorage-remember.html
File metadata and controls
73 lines (53 loc) · 1.51 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html>
<head>
<title>Local Storage</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
//create a function that adds css to show something
var showSomething = function(){
$("#something").css({
"width":"500",
"height":"500",
"backgroundColor":"orange"
});
};
//create a function to hide something
var hideSomething = function(){
$("#something").hide();
};
//set up a click event to show somehting
$("#show").click(function(){
//store the value
localStorage.setItem("something","visible");
console.log("set the value to 'visible'");
//run the showSomething function
showSomething();
});
//set up a click event to hide somehting
$("#hide").click(function(){
//remove the item that was stored
localStorage.removeItem("something");
console.log("removed item");
//run the hideSomething function
hideSomething();
});
//find out if something should be shown
var somethingState = localStorage.getItem("something");
if(somethingState === "visible") {
console.log("set the value to 'visible' because that is what was last set");
//show something!
showSomething();
}
});
</script>
</head>
<body>
<ul>
<li id="show">show something</li>
<li id="hide">hide something</li>
</ul>
<div id="something"></div>
</body>
</html>