Skip to content

Commit 0f52f47

Browse files
committed
lesson 16
1 parent 3bc795a commit 0f52f47

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

app.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,19 @@ hideBox.addEventListener('change', function(e){
4242
} else {
4343
list.style.display = "initial";
4444
}
45-
});
45+
});
46+
47+
// filter books
48+
const searchBar = document.forms['search-books'].querySelector('input')
49+
searchBar.addEventListener('keyup', function(e){
50+
const term = e.target.value.toLowerCase()
51+
const books = list.getElementsByTagName('li');
52+
Array.from(books).forEach(function(book){
53+
const title = book.firstElementChild.textContent;
54+
if(title.toLowerCase().indexOf(term) != -1){
55+
book.style.display = 'block';
56+
} else {
57+
book.style.display = 'none';
58+
}
59+
})
60+
})

0 commit comments

Comments
 (0)