On the front page, there are approximately 16 posts displayed along with a filter featuring 4 drop-down menus showcasing post categories. I have assigned category names as classes to each post div and am currently using javascript to hide them.
The code snippet below is utilized for filtering posts:
$('#filter select').change(function () {
var upper = $('#upper').val(); //these are 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 represents the class of the post container which functions flawlessly.
The initial option in every dropdown menu is labeled "ALL," which I aim to make functional.
For instance, selecting ALL in the "TOE" dropdown menu should retain the current results while also displaying posts that belong to any TOE category.
I attempted to identify all values from the TOE dropdown menu using the following code:
var toeall = new Array();
$('#toe option').each(function() {
toeall.push('.'+$(this).val());
});
if(toe=="all")
{
$('.box').hide().filter(classes&&toeall).show();
}
While aware of the inaccuracies in the above code, could someone provide guidance on how to correct it?
UPDATE: http://jsfiddle.net/kd3ybnnx/1/ <- Demo after answer from madalin ivascu