Created
December 2, 2011 22:36
-
-
Save jesalg/1425167 to your computer and use it in GitHub Desktop.
JavaScript List Filter
This file contains 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
// Custom css expression for a case-insensitive contains() | |
$.expr[':'].Contains = function(a,i,m){ | |
return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase())>=0; | |
}; | |
// Search function for Find Partners | |
var listFilter = function() { | |
var input = $("input.filterinput"); | |
var list = $("#list"); | |
$(input).bind('change',function(){ | |
var filter = $(this).val(); | |
if(filter) { | |
// this finds all li in an ul that contain the input, | |
// and hide the ones not containing the input while showing the ones that do | |
$(list).find("li:not(:Contains(" + filter + "))").slideUp(); | |
$(list).find("li:Contains(" + filter + ")").slideDown(); | |
} else { | |
$(list).find("li").slideDown(); | |
} | |
return false; | |
}); | |
$(input).bind('keyup',function(){ | |
// fire the above change event after every letter | |
$(this).change(); | |
}); | |
} | |
listFilter(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment