Get function work for new loaded elements

Get function work for new loaded elements

Hello,
I am in front of a problem. I know this was discussed in this forum already but this didn't really help me.
I am loading content with $.ajax and I am receiving a bunch of elements. ( In this case "posts" ). Now I wanted to work on and make the like / share function work but the elements don't react to the click. I already tried the .on() thing out. Either I did it wrong or it just does not work. I hope you can help me.

  1. // Load content
  2. var first_post;
  3. var last_post;
  4. $(document).ready(function(){
  5. $.ajax({
  6. type: "post",
  7. url: "lib/php/database.lib.php",
  8. data: {action: "loadPosts", limit: 10},
  9. success: function(returned) {
  10. $("#main-wrapper .content.right #left #posts #userpost-content").append(returned);
  11. first_post = $("#main-wrapper .content.right #nbcontent #posts .user-post").first().attr("id");
  12. last_post = $("#main-wrapper .content.right #nbcontent #posts .user-post").last().attr("id");
  13. }
  14. });
  15. });
  16. $("#main-wrapper .content.right #nbcontent #posts .user-post").on("click", "div.like", function(){
  17. alert("OK");
  18. });