Visitar URL original
items check update in localStorage · wesbos/JavaScript30@1a91396 · GitHub
Skip to content

Commit 1a91396

Browse files
committed
items check update in localStorage
1 parent dfb6052 commit 1a91396

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

‎15 - LocalStorage/index-START-y.html‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,21 @@ <h2>LOCAL TAPAS</h2>
5959
}
6060

6161
function toggleDone(e){
62-
62+
if(!e.target.matches('input'))return; //skip unless it's an input
63+
const el = e.target;
64+
const index = el.dataset.index;
65+
items[index].done = !items[index].done;
66+
localStorage.setItem('items', JSON.stringify(items));
67+
// console.log(e.target);
6368
}
6469

6570
addItems.addEventListener('submit', addItem);
6671
populateList(items, itemsList);
6772

68-
const checkboxes = document.querySelectorAll('input');
69-
checkboxes.forEach(input =>input.addEventListener('click', () => alert('hi')));
73+
itemsList.addEventListener('click', toggleDone);
74+
75+
// const checkboxes = document.querySelectorAll('input');
76+
// checkboxes.forEach(input =>input.addEventListener('click', () => alert('hi')));
7077
</script>
7178

7279

0 commit comments

Comments
 (0)