Looping using jquery's .each

Wednesday, July 9, 2014

I have a string of dates in which I wish to truncate at the first comma. e.g., I would like:



  • Today, July 9, 2014

  • Tomorrow, July 10, 2014

  • July 11, 2014


To Display:


Using:



var longDay = $('.daily_forecast').text();
var shortDay = jQuery.trim(longDay).substring(0, 12).split(',').slice(0, -1);
$('.daily_forecast').replaceWith('<span>' + shortDay + '</span>');


will properly truncate the content, however, all results are returning "Today".


I believe I need to loop through the elements using .each but am having difficulty doing so.


Thank you.







http://ift.tt/1oCbDaK