1

Jquery:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/timeago.js" ></script>

$(document).ready(function(){
   jQuery("abbr.timeago").timeago();
});

html:

<abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>
function Refresh() {
    setTimeout(function(){      
        <?php echo 'var id = '.json_encode($_GET['id']).';'; ?>
        $('#cmdz').load('cmdajax.php?id='+id);  
    },1000);
}

The #cmdz div contains the abbr tag. timeago working properly in onload but when the div is refreshed it won't works.

for some reason jQuery("abbr.timeago").timeago(); function not working. Here you can find full code:after ajax call jquery function not working properly

Community
  • 1
  • 1
sudeep cv
  • 1,017
  • 7
  • 20
  • 34

3 Answers3

4

Try out Livestamp.js. It's unobtrusive and auto-updating. All you need to provide is the Unix timestamp.

Matt Bradley
  • 4,395
  • 1
  • 20
  • 13
  • 2
    I could not get timeago to work on dynamically-created tags, even if I ran `$("abbr.timeago").timeago();` after every DOM insertion. It worked on the static elements, but ignored the dynamic ones. Livestamp worked just fine, including on dynamic elements. – gbe Oct 08 '14 at 07:24
  • Unfortunately, Livestamp.js (671 bytes) depends on Moment.js (15 kb). Would be nice to use Livestamp.js with native Javascript date objects, and avoid all that overhead. Regardless, thank you for creating Livestamp! – tim-montague Jun 06 '16 at 13:33
2

Working demo http://jsfiddle.net/FFeE3/1/

Can you please try sourcing your time ago.js from below link and any particular reason you are using jQuery("abbr.timeago").timeago(); you can use $("abbr.timeago").timeago();

Hope this helps rest demo should give you more idea. cheers

Script

  <script type='text/javascript' src="https://github.com/petersendidit/jquery-timeago/raw/master/jquery.timeago.js"></script>

code

$("abbr.timeago").timeago();​
Tats_innit
  • 33,991
  • 10
  • 71
  • 77
  • Thanks for the live timeago.js . But $("abbr.timeago").timeago();​ still not working . I think the abbr tag in a ajax response that may hurt my cod right? – sudeep cv Jun 19 '12 at 11:39
  • Hiya, @Compiler code in ajax request? hmm are you adding the element dynamically? in that case you will trigger the Jquery when the htl is added. :) hope it helps cheers – Tats_innit Jun 19 '12 at 11:49
  • added $("abbr.timeago").timeago(); to Refresh() but still not working. – sudeep cv Jun 19 '12 at 13:00
1

Two way of representation, Do this way or other way but don't mix:-

jQuery(document).ready(function() {
  jQuery("abbr.timeago").timeago();
});

OR

$(document).ready(function() {
  $("abbr.timeago").timeago();
});
Siva Charan
  • 17,940
  • 9
  • 60
  • 95