Hey, I am trying to create a search field that will filter or show/hide(which ever is best) the list elements based on what the user typed in and clicked the search button. I have no idea how to do this. everything I tried does not work unfortunately and im unsure of the best approach for this, like do i use show and hide or is there something better?
This is my HTML:
<html>
<head>
</head>
<body>
<label for="filter">Filter</label>
<input type="text" name="filter" value="" id="filter" />
<a id="addtag" href="#">Search</a>
<ul>
<li id="Hero1">Superman</li>
<li id="Hero2">Batman</li>
<li id="Hero3">Spiderman</li>
<li id="Hero4">Iron Man</li>
<li id="Hero5">The Hulk</li>
</ul>
</body>
</html>
So, if someone types in 'Superman' and clicks the search button, then only the Superman list element will be displayed.
Any help on this would be great. Thanks.
Very basic version, but no need of plugins and it works:
This uses jQuery and creates a sliding animation, too. This would be the HTML:
JavaScript
CSS is optional. JSFiddle Demo: http://jsfiddle.net/4feug/
You might be better off using a jQuery Search Plugin, like this one.
A little improvement to duckyflip's answer to make the search case-insensitive: