Skip to content

Instantly share code, notes, and snippets.

@seyhunak
Created December 17, 2011 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seyhunak/1490318 to your computer and use it in GitHub Desktop.
Save seyhunak/1490318 to your computer and use it in GitHub Desktop.
Searching Lists with JQuery
$(document).ready(function () {
$('#search').keyup(function(event) {
var search_text = $('#search').val();
var rg = new RegExp(search_text,'i');
$('#product_list .product-list .product').each(function(){
if($.trim($(this).html()).search(rg) == -1) {
$(this).parent().css('display', 'none');
$(this).css('display', 'none');
$(this).next().css('display', 'none');
$(this).next().next().css('display', 'none');
}
else {
$(this).parent().css('display', '');
$(this).css('display', '');
$(this).next().css('display', '');
$(this).next().next().css('display', '');
}
});
});
});
$('#search_clear').click(function() {
$('#search').val('');
$('#product_list .product-list .product').each(function(){
$(this).parent().css('display', '');
$(this).css('display', '');
$(this).next().css('display', '');
$(this).next().next().css('display', '');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment