javascript - How do I use jQuery timeago to live update? -


i have value 011-04-29t14:55:33.000z value gets push jquery template. used timeago convert date elapsed time after being written template has no way of updating more time passes.

how implement automatically update?

suppose start (from timeago homepage):

<abbr class="timeago" title="2008-07-17t09:24:17z">july 17, 2008</abbr> 

now, timeago plugin change title rewrites things. need keep track of timestamp elsewhere, put in title attribute, , rerun plugin. this:

<abbr     class="timeago"     title="2008-07-17t09:24:17z"     data-ts="2008-07-17t09:24:17z" >july 17, 2008</abbr> 

will become this:

<abbr     class="timeago"     title="july 17, 2008"     data-ts="2008-07-17t09:24:17z" >2 years ago</abbr> 

and when want update it, put data-ts in title , rerun plugin:

$('.timeago').each(function() {     var $this = $(this);     $this.attr('title', $this.data('ts')); }).timeago(); 

if you're using older jquery, might need use $this.attr('data-ts') in place of $this.data('ts').


Comments