-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (34 loc) · 1.15 KB
/
index.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
let addBtn = document.getElementById("add-btn");
let clrBtn = document.getElementById("clr-btn");
let title;
let desc;
addBtn.addEventListener("click", ()=>{
ttl = document.querySelector("input").value;
description = document.querySelector("textarea").value;
let obj = {
title: ttl,
desc: description
}
let js = JSON.stringify(obj);
localStorage.setItem(localStorage.length+1, js);
console.log("updating list...");
location.reload();
});
let table = document.querySelector("table");
function listItems(){
for(let i=0; i<localStorage.length; i++){
let newRow = document.createElement("tr");
let ov = JSON.parse(localStorage.getItem(i + 1));
newRow.innerHTML = `<td>${i+1}<td>${ov.title}<td>${ov.desc}<td><button class="del-btn" onclick="delItems(${i})">Delete`;
table.appendChild(newRow);
}
}
let delBtn = document.getElementsByClassName("del-btn");
function delItems(i){
localStorage.removeItem(i+1);
location.reload();
}
clrBtn.addEventListener("click", ()=>{
document.querySelector("textarea").value = "";
});
window.onload = listItems();