I'm doing a live filter using jQuery. You can select the elements which have the string in their names or/and the elements filtering by location and/or activity. That's the idea. With my script is working ok but in separate mode. I'd like to join all the filters in just one match. How could I do it? Thanks!
$(document).ready(function (){
jQuery.expr[":"].Contains = jQuery.expr.createPseudo(function(arg) {
return function( elem ) {
return jQuery(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
};
});
$("input").keyup(function(){
$(this).change();
});
$("input").change(function(){
var filter = $(this).val().toLowerCase();
if(filter) {
$matches = $('#list_pr, #list_ba').find('a:Contains(' + filter + ')').parent();
$('li', '#list_pr, #list_ba').not($matches).slideUp();
$matches.slideDown();
}else{
$('#list_pr, #list_ba').find("li").slideDown();
}
return false;
});
$("#location").change(function(){
var filter = $(this).val();
if(filter != 'default') {
$matches = $('#list_pr').find("li a[alt*="+filter+"]").parent();
$('li', '#list_pr, #list_ba').not($matches).slideUp();
$matches.slideDown();
}else{
$('#list_pr, #list_ba').find("li").slideDown();
}
return false;
});
$("#category").change(function(){
var filter = $(this).val();
alert(filter);
if(filter != 'default') {
$matches = $('#list_pr').find("li a[alt*="+filter+"]").parent();
$('li', '#list_pr, #list_ba').not($matches).slideUp();
$matches.slideDown();
}else{
$('#list_pr, #list_ba').find("li").slideDown();
}
return false;
});
});
It's a little hard to modify your code but here is an idea for you:
Of course, there is plenty of room for optimization there, but still, that is just an "idea" as a said earlier.