Skip to content
Advertisement

Hide search elements in Javascript

In the following example code I want to hide the elements that show under the search field. Code is from W3: https://www.w3schools.com/howto/howto_js_filter_lists.asp Search elements should only show when users starts typing in the search field. Nothing complex just looking for solution for beginner. Thanks

JavaScript

Advertisement

Answer

Just set display: none to #myUL li

JavaScript

and change in your js add li[i].style.display = "block"

JavaScript

Working Example

JavaScript
JavaScript
JavaScript

My approach would be different for making this search bar

JavaScript
JavaScript
JavaScript

Now in my approach if your input is empty no list-item is visible.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement