Created
December 17, 2011 14:18
-
-
Save seyhunak/1490318 to your computer and use it in GitHub Desktop.
Searching Lists with JQuery
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
$(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