shortysbest Posted November 26, 2010 Share Posted November 26, 2010 I am trying to automatically update the time of comments (much like facebook says "just a moment ago, a few seconds ago, 15 minutes ago, etc.) I have it working as far as updating one of the comments' dates, but cannot get it to update each one all the way down through them. example: Comment 1 Date <---this one updates, but none of them below do Comment 2 Date Comment 3 Date Comment 4 Date my html for the div of the id is: <div id="<?php print $id?>" class="comment-date"><?php print time_stamp($date)?></div> (id is the unique id of the comment) $(document).ready(function(){ setInterval(function() { var id = $(".comment-date").attr("id"); $.ajax({ type: "POST", url: "ajaxpages/php/update_date.php", data: "comment_id="+id, cache: false, success: function(html){ $("#"+id+" .comment-date").html(html); } }); }, 100);}); Quote Link to comment https://forums.phpfreaks.com/topic/219873-update-a-number-of-divs-at-a-certain-interval-partially-working/ Share on other sites More sharing options...
trq Posted November 26, 2010 Share Posted November 26, 2010 $(document).ready(function(){ setInterval(function() { $(".comment-date").each(function() { var $element = $(this); var id = $element.attr('id'); $.ajax({ type: "POST", url: "ajaxpages/php/update_date.php", data: {comment_id: id}, cache: false, success: function(html) { $element.html(html); } }); }); }, 100); }); Quote Link to comment https://forums.phpfreaks.com/topic/219873-update-a-number-of-divs-at-a-certain-interval-partially-working/#findComment-1139774 Share on other sites More sharing options...
shortysbest Posted November 26, 2010 Author Share Posted November 26, 2010 Beautiful, Thank you very much, seems to be working how I want it to. Quote Link to comment https://forums.phpfreaks.com/topic/219873-update-a-number-of-divs-at-a-certain-interval-partially-working/#findComment-1139779 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.