jquery - Want to keep "ALL" option in Javascript-CSS filter -


there 16 posts in front page , there filter 4 drop-downs showing post categories. have added category names classes post div , i'm hiding them javascript.

used following code filter posts.

$('#filter select').change(function () { var upper = $('#upper').val(); //these ids of select. var sole = $('#sole').val(); var toe = $('#toe').val(); var midsole = $('#midsole').val();    var classes = '.' + [upper, sole, toe, midsole].join('.'); $('.box').hide().filter(classes,toeall).show();  }); 

.box class of post container. works perfectly.

the first option in each dropdown "all" , want make work.

for example, if select in "toe" dropdown, has keep existing results , and show posts has 1 of toe categories class.

using following code tried find values of toe dropdown , show posts classes too.

var toeall = new array();  $('#toe option').each(function() {    toeall.push('.'+$(this).val()); });  if(toe=="all") {     $('.box').hide().filter(classes&&toeall).show(); } 

i know code above incorrect can explain how it?

update: http://jsfiddle.net/kd3ybnnx/1/ <- demo after answer madalin ivascu

try this:

    $('#filter select').change(function () { var upper = $('#upper').val(); //these ids of select. var sole = $('#sole').val(); var toe = $('#toe').val(); var midsole = $('#midsole').val(),  array1 = [upper, sole, toe, midsole];         var ar =[];             $.each(array1,function(index,val){               if (val != 'all') {//note value of option has                   ar.push(val);                }              });         if(ar.length == 0) {$('.box').show();} else {            var classes = '.' + ar.join('.');             $('.box').hide().filter(classes).show();          }         }); 

jsfiddle: http://jsfiddle.net/kd3ybnnx/4/


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -