Suppose you start with this (from the timeago homepage):
<abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>
The timeago plugin will now change the title as it overwrites things. All you have to do is track the timestamp elsewhere, return it to the title attribute and rerun the plugin. Something like that:
<abbr class="timeago" title="2008-07-17T09:24:17Z" data-ts="2008-07-17T09:24:17Z" >July 17, 2008</abbr>
This will become the following:
<abbr class="timeago" title="July 17, 2008" data-ts="2008-07-17T09:24:17Z" >2 years ago</abbr>
And if you want to update it, just return data-ts to title and restart the plugin:
$('.timeago').each(function() { var $this = $(this); $this.attr('title', $this.data('ts')); }).timeago();
If you are using old jQuery, you may need $this.attr('data-ts') instead of $this.data('ts') .
source share