dimanche 9 août 2015

How to link a checkbox(:checked) to a class?

I have setup a filter list witch checkboxes. When the specific checkbox is checked, i need to interact with a class so it hides through JavaScript. Also, if multiple checkboxes are checked, i need to show these items with both the classes. I have this:

HTML:

    <div class="categsort">
            <input class="hide-checkbox" type="checkbox" id="tagriot" value="riot" style="display: none;">
            <label for="tagriot">RIOT</label>
    </div>

JavaScript:

     function updateContentVisibility(){
     var checked = $('#filters :checkbox:checked');
     if(checked.length){
          streameach.hide();
          checked.each(function(){
              $("." + $(this).val()).show();
           });
     } else {
          streameach.show();
          }
     }

     $('#filters :checkbox').click(updateContentVisibility);
     updateContentVisibility();

And then i also have

     <div class="riot">...</div>

Now when the checkbox is clicked, it hides all the divs, but doesn't show the ones that should be connected to that checkbox. (I have multiple checkboxes.)




Aucun commentaire:

Enregistrer un commentaire