Just use .length, to check if it exists, after an append()
$('#elemId').length;
Like so...
if($('#elemId').length > 0){ //your code here };
Or write your own function....
jQuery.fn.Exists = function(){
return jQuery(this).length > 0;
};
Then use it to return true or false...
if($('#elemId').Exists()){ //your code here };
Or you can use the livequery() plugin...
$('#elemID').livequery(function()
{
// do things here like binding new events and stuff.
// this function is called when an object is added.
// check the API for the deletion function and so on.
});
I can't seem to find the plugin anymore, on the jQuery website, but it did exist at one point
You can also try DOMNodeInserted...
$(document).bind('DOMNodeInserted', function(e) {
console.log(e.target, ' was inserted');
});
You can use on()....if your selector will always be the same...
So for instance, say as you scroll you're always adding a new div called class="newDiv"....
Then the jquery you want to perform....if you want to bind an event to click...
$(document).on( 'click', '.newDiv', function(){ //your code here
});