Comments are loaded from the database. Comments have several levels, i.e. answers to them. The problem is that the 1st and 2nd levels of comments are output, but there is no further. I define where the attachment is by the ID of the comment itself and the level of the comment / answer itself. I understand that js sees elements on the page at the time of initialization of the code. But how can I add "answers" in this case, if the elements are created dynamically? Tell me how to work with dynamic elements, otherwise I don’t know what to do ... I use this construction:
var commLevel = o[i].level, commId = o[i].id_comments; switch (commLevel) { case '0': item.addClass('first_lvl') $('.commentlist').append(item); break; case '1': item.addClass('reply second_lvl') $('.first_lvl.id_' + commId).append(item); break; case '2': item.addClass('reply third_lvl') $('.second_lvl.id_' + commId).append(item); break; case '3': item.addClass('reply fourth_lvl') $('.third_lvl.id_' + commId).append(item); break; case '4': item.addClass('reply fifth_lvl') $('.fourth_lvl.id_' + commId).append(item); break; default: console.log('Error');