Q:

Newly Added Classes Not Behaving As The Ones Loaded on DOM Ready

I am using timeago.js, a jQuery plugin to show that an article was posted 2 minutes ago. 
HTML:
<p> Articles <span class='post-time' title='2014-12-03 13:42'></span> </p>

jQuery:
$('.post-time').each(function(){
    var $this = $( this );
    $this.timeago();
})

This works on classes that are loaded on DOM ready and I have a result that look like this:
First Article: less than 1 minute ago
Second Article: 4 minutes ago
Third Article: 1 hour ago
But the ones loaded via AJAX are not working. They don't show anything. 
What do I do to make it work?

A:

A quick suggestion is:
$.ajax({
     ...
     success:function(){
       // code for prepending
       $('.post-time:first').timeago();
     },
     complete:function(){
        // even you can call it here too.
     }
});

or:
make a global function and call it in your ajax success:
function setTimeago(){
    $('.post-time').each(function(){
        var $this = $( this );
        $this.timeago();
    });
}

$.ajax({
     ...
     success:function(){
       // code for prepending
       setTimeago(); // call here then
     },
     complete:function(){
        // even you can call it here too.
     }
});

