vendredi 27 mai 2016

jQuery hide on checkbox multiple values

I have 7 checkboxes with all a different ID. Those ID's correspondent with div's containing an data-methode in it. Clicking on a checkbox will hide all div's except for that one with the corresponding ID.

At this moment that works! But when I select multiple checkboxes all the divs disappear.

This is my javascript:

<script type="text/javascript"> 
jQuery('.filter_methode input').change(function()
    {
        jQuery('.featured-item-container').show();
        jQuery('input').each(function()
            {
            var Checked;
            if(Checked = jQuery(this).attr('checked'))
                {
                    jQuery(".featured-item-container:not([data-methode='" + this.id + "'])").hide();
                };
        }); 
    });
</script>

I wonder how I can optimize this script so it listens to all selected ID's.




Aucun commentaire:

Enregistrer un commentaire