Skip to content

Commit f166e3a

Browse files
author
iamshaunjp
committed
lesson 16 code
1 parent 9a8131c commit f166e3a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

app.js

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

0 commit comments

Comments
 (0)