File tree Expand file tree Collapse file tree 2 files changed +23
-12
lines changed
Expand file tree Collapse file tree 2 files changed +23
-12
lines changed Original file line number Diff line number Diff line change 33 < head >
44 < meta charset ="UTF-8 " />
55 < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6- < title > Search Bar</ title >
7- < link rel ="stylesheet " href ="style.css " />
6+ < title > Search Bar Example </ title >
7+ < link rel ="stylesheet " type =" text/css " href ="style.css " />
88 </ head >
9+
910 < body >
1011 < div class ="container ">
1112 < input
12- class ="searchbar "
13+ id ="searchbar "
1314 onkeyup ="search_animal() "
1415 type ="text "
1516 name ="search "
16- placeholder ="search... "
17- >
18- < ul id ="list ">
19- < li class ="option "> Girl</ li >
20- < li class ="option "> cat</ li >
21- < li class ="option "> Dog</ li >
22- < li class ="option "> Mouse</ li >
17+ placeholder ="Search animals.. "
18+ />
19+
20+ < ul id ="list ">
2321 < li class ="option "> Apple</ li >
2422 < li class ="option "> Banana</ li >
2523 < li class ="option "> Elephant</ li >
119117 < li class ="option "> Infusion</ li >
120118 < li class ="option "> Cascade</ li >
121119 < li class ="option "> Symphony</ li >
122- </ ul >
123- </ input >
120+ </ ul >
124121 </ div >
122+
125123 < script src ="script.js "> </ script >
126124 </ body >
127125</ html >
Original file line number Diff line number Diff line change 1+ function search_animal ( ) {
2+ let input = document . getElementById ( "searchbar" ) . value . toLowerCase ( ) ;
3+ let x = document . getElementsByClassName ( "animals" ) ;
4+ let animalsArray = Array . from ( x ) ;
5+
6+ animalsArray . forEach ( ( animal ) => {
7+ if ( ! animal . textContent . toLowerCase ( ) . includes ( input ) ) {
8+ animal . style . display = "none" ;
9+ } else {
10+ animal . style . display = "list-item" ;
11+ }
12+ } ) ;
13+ }
You can’t perform that action at this time.
0 commit comments