-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (31 loc) · 1.58 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
const wishListinputElement= document.querySelector(".input");
const addwishlistbutton= document.querySelector(".button");
let wishlistvalue="";
const parentwishlistcontainer= document.querySelector(".wishlist-container");
let wishlist=[];
const form= document.querySelector(".form");
wishListinputElement.addEventListener('keyup',(event) => {wishlistvalue=event.target.value;});
form.addEventListener('submit',(event) => { event.preventDefault();
wishlist=[...wishlist,wishlistvalue];wishListinputElement.value="";parentwishlistcontainer.innerHTML=""; showwishlist(wishlist);})
const showwishlist = (wishlist) => {
for (let item of wishlist){
const containerelement= document.createElement('div');
const checkboxelement =document.createElement('input');
checkboxelement.setAttribute('type','checkbox');
containerelement.appendChild(checkboxelement);
const wishlisttextelement = document.createElement('span');
wishlisttextelement.innerText = item;
containerelement.appendChild(wishlisttextelement);
const deletebuttonelement= document.createElement('button');
deletebuttonelement.innerText='delete'
deletebuttonelement.setAttribute('name',item);
containerelement.appendChild(deletebuttonelement);
parentwishlistcontainer.appendChild(containerelement);
}
}
parentwishlistcontainer.addEventListener('click',(event) => {
const itemtodelete=event.target.name;
wishlist=wishlist.filter(i => i!==itemtodelete);
parentwishlistcontainer.innerHTML='';
showwishlist(wishlist);
})