File tree Expand file tree Collapse file tree 3 files changed +34
-10
lines changed
Expand file tree Collapse file tree 3 files changed +34
-10
lines changed Original file line number Diff line number Diff line change @@ -32,5 +32,29 @@ li.appendChild(bookName);
3232li . appendChild ( deleteBtn )
3333list . appendChild ( li ) ;
3434
35-
3635} ) ;
36+
37+ //hide books
38+ const hideBox = document . querySelector ( '#hide' ) ;
39+ hideBox . addEventListener ( 'change' , function ( e ) {
40+ if ( hideBox . checked ) {
41+ list . style . display = 'none' ;
42+ } else {
43+ list . style . display = 'initial' ;
44+ }
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+ } ) ;
Original file line number Diff line number Diff line change 1111 < div id ="page-banner ">
1212 < h1 class ="title "> Bookorama</ h1 >
1313 < p > Books for Ninjas</ p >
14- < a href ='http://www.thenetninja.co.uk '> the net ninja</ a >
1514 < form id ="search-books ">
1615 < input type ="text " placeholder ="Search books... " />
1716 </ form >
@@ -39,6 +38,8 @@ <h2 class="title">Books to Read</h2>
3938 </ ul >
4039 </ div >
4140 < form id ="add-book ">
41+ < input type ='checkbox ' id ='hide '/>
42+ < label for ='hide '> Hide all books</ label >
4243 < input type ="text " placeholder ="Add a book... " />
4344 < button > Add</ button >
4445 </ form >
Original file line number Diff line number Diff line change @@ -115,16 +115,15 @@ h1, h2{
115115 clear : both;
116116}
117117
118- /*
119- #tabbed-content li{
120- display: inline-block;
121- padding: 10px 14px;
122- background: #ddd;
123- border-radius: 4px;
124- cursor: pointer;
125- margin-right: 10px;
118+ # add-book # hide {
119+ width : 30px ;
126120}
127121
122+ # add-book label {
123+ line-height : 52px ;
124+ }
125+
126+ /*
128127#tabbed-content .tab{
129128 display: none;
130129 border: 1px solid #ddd;
You can’t perform that action at this time.
0 commit comments