-
Notifications
You must be signed in to change notification settings - Fork 0
/
localStorage.js
57 lines (41 loc) · 1.57 KB
/
localStorage.js
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
// let topName= document.querySelector(".Name");
// let inputBox = document.querySelector("input-box");
// let buttonBox = document.querySelector(".button-box");
// topName.innerText="Sahil";
// buttonBox.addEventListener("click",()=>{
// console.log("hello")
// }
// );
let topName = document.querySelector(".Name");
let inputBox = document.querySelector(".input-Box");
let ageBox = document.querySelector(".age-Box");
let ageName = document.querySelector(".age");
// topName.innerText = localStorage.getItem("myName");
// ageName.innerText = localStorage.getItem("age");
// inputBox.addEventListener("input", (e) => {
// localStorage.myName = e.target.value;
// topName.innerText = localStorage.myName;
// });
// ageBox.addEventListener("input", (e) => {
// localStorage.age = e.target.value;
// ageName.innerText = localStorage.age;
// });
const myData =JSON.parse(localStorage.getItem('myData')) // our object which store in storage as a string now converted to object again n we
// use the poperties in line 52,53
// myData={
// name:'',
// age:'',
// }
inputBox.addEventListener('input' , (e)=>{
myData.name = e.target.value;
localStorage.setItem('myData' ,JSON.stringify(myData));
topName.innerText=e.target.value;
// topName.innerText=localStorage.getItem(myData); // we cnt get our name in the <h> tag
})
ageBox.addEventListener('input' , (e)=>{
myData.age = e.target.value;
localStorage.setItem('myData' ,JSON.stringify(myData));
ageName.innerText=e.target.value;
})
ageName.innerText =myData.age;
topName.innerText =myData.name;