Skip to content

Instantly share code, notes, and snippets.

@neall
Created July 8, 2011 14:34
Show Gist options
  • Save neall/1071970 to your computer and use it in GitHub Desktop.
Save neall/1071970 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>test filtering</title>
</head>
<body>
<input name=filter>
<ul>
<li>Cat</li>
<li>Dog</li>
<li>Mouse</li>
<li>Gecko</li>
<li>Parrot</li>
</ul>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script>
(function(){
var lastFilterString = '';
$('input').bind('change keydown keyup click', function(){
var $input = $(this);
var filterString = $input.val();
if (lastFilterString !== filterString) {
$('li').each(function(){
var $li = $(this);
if ($li.text().indexOf($input.val()) > -1) {
$li.show();
} else {
$li.hide();
}
});
}
lastFilterString = filterString;
});
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment