0

I updated posts in homepage with query load function. It enables me to show actual posts. However, I have a problem. That is: When I updated all posts without refresh whole page, I want to control element which loaded with load jquery function. I loaded all actual post with this:

$( ".all-posts" ).load("/ .all-posts");

.all-posts element consists of .post-edit class name.

I want to find with this function:

$('.post-edit').click(function(){ 
alert("found element");
});

I fixed the problem with: I define function outside of load function and I used it normally and in load function's callback function.

1 Answers1

1

You can make use of event delegation.

Replace:

$('.post-edit').click(function(){ 
  alert("found element");
});

with:

$('.all-posts').on('click', '.post-edit', function () { 
  alert("found element");
});
Jeto
  • 13,447
  • 2
  • 22
  • 39