Created
July 8, 2011 14:34
-
-
Save neall/1071970 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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