I have a container which contains divs of the same format. Each div has 3 attributes in which I am applying filter options to.
the div looks like this
<div data-A="1" data-B="x" data-C="4"
>
Each of the 3 options, A B and C has values for each option. For example A has values 1 2 3, B has values x y z, C has values 4 5 6. They are available as checkboxes like this
So if I checked an A option with value = 1, the div that has data-A = 1 will show, so if I checked A option with value = 1, B option with value = x and C option with value = z, divs that fulfil these 3 values will be shown.
However, how do I actually cater to situations in which one of the A,B and C is not chosen as a filter at all, ie checked B option with value = x and C option with value = 4, so I should be showing all divs with data-B = 'x' and data-C = '4'.
right now, I am using 3 nested for loops for this, which will not cater to the situation in which one option is not chosen. Is there any way to do this efficiently?
My jquery for now is as below
for(var p = 0;p < $(A).length ;p++)
{
for(var q = 0;q < $(B).length ;q++)
{
for(var r = 0;r < $(C).length ;r++)
{
$('div[data-A = "'+ A[p] + '"][data-B="'+ B[q] +'"][data-C="'+ C[r] +'"]').show();
}
}
}