Created
March 11, 2013 05:22
-
-
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>
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
$('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