The on method will handle events for the currently selected elements when it is executed first, or any future elements that raise a specific event corresponding to a particular selector. Since an element added to the page does not automatically generate a load event or any other type, your code will never be executed for your newly added elements.
You have two options. The first is to trigger a custom event whenever your new item is inserted. For example,
$.get("/newElemnet", function(newElement) { $('#placeToInsertElement').append(newElement); $(newElement).trigger('newElementAdded'); });
Then your original function will listen for this custom event:
$(function(){ $("body").on("newElementAdded", ".this_button", function() { console.log("its been loaded"); }); });
The second option is to constantly poll for new items, as described in this question .
amurra
source share