$("input.filter-checkbox").change(function(){
var categories = [],gender = [],brands = [];
//push to array if checked and remove from array if unchecked
$('input.filter-checkbox:checked').map(function() {
var checkbox_id = $(this).attr("id");
var val = $(this).data("ty-value");
//push to categories array if checkbox is category filter
if(checkbox_id.indexOf("categoryMain") >= 0){ categories.push(val); }
//push to gender array if checkbox is gender filter
if(checkbox_id.indexOf("genderMain") >= 0){ gender.push(val); }
//push to brands array if checkbox is brands filter
if(checkbox_id.indexOf("brandMain") >= 0){ brands.push(val); }
}).get();
if(categories.length > 0 || gender.length > 0){
var show = {
'pc': categories
};
console.log(show);
$("div.product-box").hide().filter(function(){
// Only returns true for elements
// that satisfy all three arrays
for (var i in show) {
var attr = $(this).attr(i),
match = ('|' + show[i].join('|') + '|').indexOf(attr) > -1;
if (!match) {
return false;
}
}
// If we reach this point then we can assert
// that the element contains all required attributes
return true;
})
.show();
}else{
$("div.product-box").show();
}
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.