'how to exclude jQuery checkbox results

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/



Solution 1:[1]

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/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Irvin Dominin