+6  A: 

This is because the .each() loops through the matched elements when it was run...the new elements weren't there to do things to when you called it. Solution: call it again, but only for the new elements when you add them. You need to call the same .each() on your ajax result, with the context of the result to restrict the each to it.

For example if you have this currently:

$(".myDiv").each(function() {
 //stuff here
});

You need to call the same selector and same code in your success (or complete, whatever you're using) ajax function like this:

success: function(resp) {
  $(".myDiv", resp).each(function() { //each, but only on the new guys
   //stuff here (same as before)
  });
  //Do more stuff with your response...
}

The key here is the , resp bit, it tells jQuery to select the same elements you were before, but only inside the context in the second parameter, in this case: your ajax response containing the new elements that need love.

Update based on new question code

First, you can shorten your code here (optional not required):

$('#chk-selected').change(function(){
    if($(this).is(':checked')) {
        $(".lib-item.item-selected").slideDown('fast');
    }
    else {
        $(".lib-item.item-selected").slideUp('fast');
    }
});

In the callback, trigger the that same handler to run again (this won't change the selection, just trigger the handler to run):

onComplete: function(event, queueID, fileObj, response, data)
{
    $(".blank").remove();
    $("#lib-contentWrap").append(response); 
    $('#chk-selected', response).trigger('change');
}
Nick Craver
I tried this but it doesn't work... And duplicating code doesn't sound a nice practice at all as it increases the chance of bugs and needs more support.
Primoz Rome
You don't need to duplicate code. You can assign a name to the function and use it in both places.
Carles
Yes sure that's correct, but anyway the solution didn't work for me... I've copied my .each code in my onComplete function, where I add new elements, but the each still worked only on original elements.
Primoz Rome
@Primoz Rome - Updated the answer for your specific posted code, let me know if it gives you any problems.
Nick Craver
@Nick: I think it should be `.lib-item.item-selected` - with no space in between - you're checking whether `.lib-item` hasClass `.item-selected`
Adam Kiss
@Adam - Thanks, need caffeine before answering this early :)
Nick Craver
@Nick - I already have some caffeine in my blood, so it was easy to spot it for me :D
Adam Kiss
@Nick and Adam: thanks guys this helped solve me the problem. I did read some additional FAQ on jQuery and things are lot clearer to me now how it works behind the scenes. Thanks again Nick for even going into code for me. Priceless!
Primoz Rome
A: 

Id say have a look at the jquerry live operator http://api.jquery.com/live/. It attaches a handler to the event for all elements which match the current selector, now or in the future.

pre10dr