Skip to content

Instantly share code, notes, and snippets.

@marcoceppi
Created August 7, 2011 17:50
Show Gist options
  • Save marcoceppi/1130582 to your computer and use it in GitHub Desktop.
Save marcoceppi/1130582 to your computer and use it in GitHub Desktop.
Dynamic filtering
(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