Skip to content

Instantly share code, notes, and snippets.

@jeremejazz
Created March 11, 2013 05:22
Show Gist options
  • Save jeremejazz/5132054 to your computer and use it in GitHub Desktop.
Save jeremejazz/5132054 to your computer and use it in GitHub Desktop.
Simple text search filter. Searches through a list of items on keypress of a textbox. #filtersearch is the ID for the html input field. #list is the ID of the <ul>
$('input#filtersearch').bind('keyup change', function () {
if ($(this).val().trim().length != 0) {
$('#list li').show().hide().each(function () {
if ($(this).is(':icontains(' + $('input#filtersearch').val() + ')'))
$(this).show();
});
}
else {
$('#list li').show().hide().each(function () {
$(this).show();
});
}
});
$.expr[':'].icontains = function (obj, index, meta, stack) {
return (obj.textContent || obj.innerText || jQuery(obj).text() || '').toLowerCase().indexOf(meta[3].toLowerCase()) >= 0;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment