jquery - Call javascript function multiple times -
jquery - Call javascript function multiple times -
so, i'm having troubles finding way solve problem. know seems silly, i'm stuck on this.
i have like:
<div class="tdate"> sat oct 11 01:11:01 +0000 2014 </div> <div class="tdate"> sat oct 11 01:10:44 +0000 2014 </div> <div class="tdate"> sat oct 11 00:51:03 +0000 2014 </div>
and javascript function:
function parsetwitterdate(tdate) { var system_date = new date(date.parse(tdate)); var user_date = new date(); if (k.ie) { system_date = date.parse(tdate.replace(/( \+)/, ' utc$1')) } var diff = math.floor((user_date - system_date) / 1000); if (diff <= 1) {return "just now";} if (diff < 20) {return diff + " seconds ago";} if (diff < 40) {return "half min ago";} if (diff < 60) {return "less min ago";} if (diff <= 90) {return "one min ago";} if (diff <= 3540) {return math.round(diff / 60) + " minutes ago";} if (diff <= 5400) {return "1 hr ago";} if (diff <= 86400) {return math.round(diff / 3600) + " hours ago";} if (diff <= 129600) {return "1 day ago";} if (diff < 604800) {return math.round(diff / 86400) + " days ago";} if (diff <= 777600) {return "1 week ago";} homecoming "on " + system_date; } var k = function () { var = navigator.useragent; homecoming { ie: a.match(/msie\s([^;]*)/) } }();
what i'm trying alter .tdate new format (which javascript does). dont know how phone call function alter different .tdate. if phone call parsetwitterdate("sat oct 11 00:51:03 +0000 2014"), work, 1 time.
basically, want see date on page format: "sat oct 11 01:11:01 +0000 2014" alter to: "47 minutes ago" (or whatever output is). dont know how phone call function parsetwitterdate(tdate).
sorry bad explanation. allow me know if don't create myself clear enough.
and give thanks much can help me.
thanks lot! :)
since using jquery (or @ to the lowest degree jquery tag used), can this
class="snippet-code-js lang-js prettyprint-override">$(function () { $('.tdate').each(function (index, value) { $(value).html(parsetwitterdate(($(value).html()))) }); });
class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="tdate"> sat oct 11 01:11:01 +0000 2014 </div> <div class="tdate"> sat oct 11 01:10:44 +0000 2014 </div> <div class="tdate"> sat oct 11 00:51:03 +0000 2014 </div>
javascript jquery html
Comments
Post a Comment