Answers for "add class if date is today"

0

add class if date is today

$(function() {
  var date = new Date(),
    currentDate = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
  $(".grid-item").each(function() {
    var specifiedDate = $(this).data('date');
    if (specifiedDate == currentDate) {
      $(this).addClass('today');
    } else if (currentDate > specifiedDate) {
      $(this).addClass('past');
    } else {
      $(this).addClass('future');
    }
  });
});
Posted by: Guest on March-01-2021

Code answers related to "add class if date is today"

Code answers related to "Javascript"

Browse Popular Code Answers by Language