-2

I'm trying to filter using a remove class jquery. when a user clicks on a radio button the tiles/boxes with the ID's should disappear. On some tiles tje category could have these values (9,2,1).

Here is my code.

// category filters
    $('input.catchk').change( function(){
        var category = this.value;

        if(category==0){
            $('.filterrowP,.filterrowC').removeClass('hidden');
        } else {
            $('.filterrowP,.filterrowC').addClass('hidden');
            $('.filterrowP,.filterrowC').addClass('hidden');
            var catlist = <?php echo $json_resP; ?>;
            var catlistc = <?php echo $json_resC; ?>;
            for (var i = 0; i < catlist.length; i++) {
                var catlp = catlist[i];
                if (catlp.category == category) {
                    $('"#ttileP'+catlp.tile_id+'"').removeClass('hidden');
                }
                 // show the items with current category
                console.log(catlp.tile_id);
            }
            for (var i = 0; i < catlistc.length; i++){
                var catlc = catlistc[i];
                if (catlc.category == category) {
                    var tilecid = catlc.tile_id;
                    $('"#tileC'+catlc.tile_id+'"').removeClass('hidden');
                }
                console.log('"#tileC'+catlc.tile_id+'"');
            }

        }
    });
Reya276
  • 109
  • 8

1 Answers1

1

Your syntax is slightly off:

$('"#ttileP'+catlp.tile_id+'"').removeClass('hidden');

should be

$('#ttileP'+ catlp.tile_id).removeClass('hidden');
Adam
  • 1,149
  • 2
  • 14
  • 21
  • 1
    The explanation for this is that surrounding the selector with individual ' will turn it into a string, adding the " will make jQuery look for a string including " in it, and you don't have a selector named that way. – Victoria Ruiz Jul 26 '18 at 17:37
  • well that removed the error but now all the tiles disappear no matter which category I select. This is suppose to act as a filter. – Reya276 Jul 26 '18 at 17:39
  • Could you put up a codepen possibly for us to see it in action? – Adam Jul 26 '18 at 17:58