Created
August 7, 2011 17:50
-
-
Save marcoceppi/1130582 to your computer and use it in GitHub Desktop.
Dynamic filtering
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
(function ($) | |
{ | |
// custom css expression for a case-insensitive contains() | |
jQuery.expr[':'].Contains = function(a,i,m) | |
{ | |
return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase())>=0; | |
}; | |
function listFilter(header, list) | |
{ | |
header.change( function() | |
{ | |
var filter = $(this).val(); | |
if(filter) | |
{ | |
$(list).find("a.email:not(:Contains(" + filter + "))").parent().slideUp(); | |
$(list).find("a.email:Contains(" + filter + ")").parent().slideDown(); | |
} | |
else | |
{ | |
$(list).find("li").slideDown(); | |
} | |
return false; | |
}) | |
.keyup( function() | |
{ | |
// fire the above change event after every letter | |
$(this).change(); | |
}); | |
} | |
//ondomready | |
$(function() | |
{ | |
listFilter($(".filter"), $(".main-content ul")); | |
}); | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment