I have a value 011-04-29T14:55:33.000Z this value gets push into a jQuery template. I used timeago to convert the date to elapsed time but after being written to the template it has no way of updating as more time passes.
How would I implement something that would automatically update?
Suppose you start with this (from the timeago homepage):
Now, the timeago plugin will change the title as it rewrites things. All you need to do is keep track of the timestamp elsewhere, put it back in the
titleattribute, and rerun the plugin. Something like this:Will become this:
And when you want to update it, just put
data-tsback intitleand rerun the plugin:If you’re using an older jQuery, you might need to use
$this.attr('data-ts')in place of$this.data('ts').