Reputation: 13
I picked up some code and it works fine, but I need one more function. If I get a result which contains A and B, the result from A only and B only should be hidden again.
$("#filters :checkbox").click(function () {
$("div").hide();
$("#filters :checkbox:checked").each(function () {
$("." + $(this).val()).show();
});
});
http://jsfiddle.net/daego/bgfy56oz/9/
Upvotes: 1
Views: 80
Reputation: 30993
You can append a string with your selected checkbox and run them as selector.
Code:
$("#filters :checkbox").click(function () {
$("div").hide();
var mySel='';
$("#filters :checkbox:checked").each(function () {
mySel+='.'+$(this).val();
});
$(mySel).show();
});
Demo: http://jsfiddle.net/6ht4zs1y/
Upvotes: 1