I'm trying to fix the problem of not repeating the timeago function to elements that have it already, but adding it to the ones that don't have it. I'm trying this but newly added abbrs are not getting activated
<abbr title="2011-09-15T12:46:26" class="timeago">less than a minute ago</abbr>
function activate_timeago(){
setInterval(function(){
$('.timeago').each(function(){
if ($(this).data('active')!='yes'){
$(this).timeago();
$(this).data('active','yes');
}
});
},60000);
}
any ideas?
ok this seems to work
Thanks to eddiemonge on #jquery
i would not activate them with an interval like you are trying, but rather immediately when creating the new item, just call a function like this one
after the ajax callback for fetching new items is done, just call:
edit just so there is no confusion, the
$('#container .new')
selector is not default jQuery,new
is a css class like any other class, you could add the classnew
to your elements when you do the ajaxcall, or you could select them in another way since you probably have just added them to the DOM in your ajax callback you already might have them available in an array ... end editbut, if you really want to continue on the interval part use this:
this function you'd only call once at the page load, downside of option two, they are not made into timeago immediately, but only after the next time the interval hits.