-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
39 lines (33 loc) · 1.14 KB
/
script.js
File metadata and controls
39 lines (33 loc) · 1.14 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
let lists = document.querySelector('.list-items');
lists.addEventListener('click', function (e) {
if (e.target.className == "name") {
const li = e.target.parentElement;
lists.removeChild(li);
}
})
const submit = document.forms['addForm'];
submit.addEventListener('submit', function (e) {
e.preventDefault()
let input = submit.querySelector('input[type="text"]').value;
input.value = '';
let li = document.createElement('li');
const deleteBtn = document.createElement('span');
li.textContent = input;
deleteBtn.textContent = ' delete';
deleteBtn.classList.add('name');
li.appendChild(deleteBtn);
lists.appendChild(li)
})
const search = document.forms['search-form'].querySelector("input")
search.addEventListener('keyup', function (e) {
const terms = e.target.value.toLowerCase();
const bookList = lists.getElementsByTagName('li');
Array.from(bookList).forEach(function (book){
const title = book.textContent
if(title.toLowerCase().indexOf(terms) != -1){
book.style.display = "block";
}else{
book.style.display = "none";
}
})
})