I am trying to filter a product list by different variants.
I have a list of sizes, then buttons for materials and different color options.
Each size will have the class name of the variant which is considered in stock. So on clicking the button the for gold you filter away all the sizes which are not tagged as gold.
What I'm trying to accomplish though is to filter with two conditions. So if you click on gold it filters away everything without a class gold, but then when you click a color option I want to filter within the already selected gold category. My code currently doesn't account for that, if you click on blue for example it shows all available sizes in blue, instead of only the blue sizes with material gold.
I also am thinking that this should work in any direction as well if you click a size it should filter the available colors and material.
This is my html:
<div class="grid grid-cols-4">
<button id="five" class="size silver gold blue">5</button>
<button id="six" class="size gold red">6</button>
<button id="seven" class="size silver red blue">7</button>
<button id="eight" class="size silver gold red">8</button>
<button id="nine" class="size gold red">9</button>
<button id="ten" class="size silver blue">10</button>
<button id="eleven" class="size gold red">11</button>
<button id="twelve" class="size silver red">12</button>
</div>
<div>
<button id="silver">silver</button>
<button id=gold>gold</button>
</div>
<div>
<button id="tsavorite">red</button>
<button id="emerald">blue</button>
</div>
and jquery:
$( document ).ready(function() {
$('#gold').on("click", function() {
$('.size').hide();
$('.gold').show();
});
$('#silver').on("click", function() {
$('.size').hide();
$('.silver').show();
});
$('#blue').on("click", function() {
$('.size').hide();
$('.blue').show();
});
$('#red').on("click", function() {
$('.size').hide();
$('.red').show();
});
});
question from:
https://stackoverflow.com/questions/65862034/jquery-filter-categories-with-multiple-conditions 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…