-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+'"');
            }

        }
    });
0

1 Answer 1

1

Your syntax is slightly off:

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

should be

$('#ttileP'+ catlp.tile_id).removeClass('hidden');
Sign up to request clarification or add additional context in comments.

3 Comments

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.
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.
Could you put up a codepen possibly for us to see it in action?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.