Javascript examples for jQuery:List
Use jQuery to loop through each list to check if there are any text values that matches the value of the input field.
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#myInput").on("keyup", function() { var value = $(this).val().toLowerCase(); $("#myList li").each(function() { $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1) });// ww w. j av a2s . c o m }); }); </script> </head> <body> <h2>Filterable List</h2> <p>Type something in the input field to search the list for specific items:</p> <input id="myInput" type="text" placeholder="Search.."> <br> <ul id="myList"> <li>First item</li> <li>Second item</li> <li>Third item</li> <li>Fourth</li> </ul> </body> </html>