-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
52 lines (47 loc) · 1.37 KB
/
Copy pathmain.js
File metadata and controls
52 lines (47 loc) · 1.37 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
var container=document.createElement("div");
container.setAttribute('class','container');
document.body.appendChild(container);
showNotes();
let addBtn = document.getElementById("add");
addBtn.addEventListener("click", function () {
let title = document.getElementById("title").value;
let note = document.getElementById("note").value;
localStorage.setItem(`${title}`, note);
store(title);
document.getElementById("note").value = "";
document.getElementById("title").value = "";
})
function showNotes() {
note = "";
title = "";
console.log("im in");
for (let key of Object.keys(localStorage)) {
store(key);
}
}
document.getElementById('clear').addEventListener('click',()=>
{
localStorage.clear();
document.location.reload(false);
})
function store(key)
{
let notes = document.createElement("div");
notes.setAttribute("class", "notes");
notes.setAttribute("id", `${key}`);
console.log(notes);
notes.innerHTML =
`
<div id="${key}" class="check" >
<h1>${key}</h1>
<h2>${localStorage[key]}</h2>
<button id="delete" onclick="deleteCard(this)">Delete</button>
</div>`;
container.appendChild(notes);
}
function deleteCard(event)
{
console.log(event.parentNode.id);
localStorage.removeItem(event.parentNode.id);
document.location.reload(false);
}