0

I'm trying to compare two dates in different formats to highlight new items added from last visit but there is one problem with first date:

jQuery( "td.details > span:last-child" ).each(function() {
  var a = jQuery( this ).text();
  var b = a.split('/');
  var c = b[1]+'/'+e[0]+'/'+e[2]; //dd.mm.yyyy=>mm.dd.yyyy
  var d = new Date( c );
  var date = d.getTime();

    jQuery('<span/>', {
    'class':'date',
    'text': date,
    }) .appendTo( "td.details > p" );
});

HTML:

    <td class="details"><p>new item1</p><span>10/1/2017 17:06</span></td>
    <td class="details"><p>new item2</p><span>09/1/2017 22:26</span></td>
    <td class="details"><p>new item3</p><span>09/1/2017 11:18</span></td>
    <td class="details"><p>new item4</p><span>08/1/2017 14:32</span></td>

Every td have different date, expectation is in every td will be created span with appropriate d.getTime() value (just testing), but newly created span contains all d.getTime() values (from every td) not only that one. What am I doing wrong?

Second date will be same(lastvisit) for every td so no problem

4

1 回答 1

0

Will this work better?

jQuery('<span/>', {
  'class':'date',
  'text': date,
}).after(this);

In your code you are appending date to every td.details > p not only the current one. .after() will add the after the your last span inside td

于 2017-01-10T17:27:46.850 回答