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'); 

  • What prevents to keep links to added items? - cpp_user
  • Those. to push them in variables? If yes, then I tried, the result is the same. Just does not work append (). But then why the second level is inserted, and then everything ... - zh-mskl9
  • 1. Rather, save to an array. 2. I do not believe. - cpp_user
  • And there is. .First_lvl is added to .commentlist, .reply.second_lvl is entered into .first_lvl and .reply.third_lvl is no longer in it - zh-mskl9
  • Bring in what you add to the append. - cpp_user

0