Appending elements to div depending on JSON data Appending elements to div depending on JSON data json json

Appending elements to div depending on JSON data


looks like your mistake is that you iterate to topCrs to show the titles, but the topCrs is a small array that already filtered and holding only one title of each category, there for you will always see only one title from each category.

what you need to do is to iterate again on all the titles again from testjson.d.results, and to filter by the category that was clicked.

var titles = testjson.d.results.filter(x => x.Category === cat);

and then to iterate this title filtered by category like that

$.each(titles, function(idx, val) {    $(".training-titles").append("<li>" + val.Title + "</li>")}