I'm using this piece of code inside of a for loop to append some content to a div:
$.get("./" + i + "/block.html", function(data){
$(data).appendTo("#id");
});
After that, I'm using this piece of code to make the added content clickable, there's a .person
div inside every block.html
:
$(".person").click(function () {
$(this).toggleClass("large");
});
This second piece of code has no effect because the first piece runs asynchronously. So the content hasn't been appended yet by the time it runs. How can I delay it until it has been?