Skip to content

Instantly share code, notes, and snippets.

@jesalg jesalg/filter.js
Created Dec 2, 2011

What would you like to do?
JavaScript List Filter
// 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");
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 {
return false;
// fire the above change event after every letter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.