[Solved] How do I add class using jquery/javascript to different elements depending on what day is it?


You don’t need jQuery to check what date it is. You can use plain Javascript for that.

var today = new Date();

if(today.getDate() === 17) {
  $('.on-17').addClass('active');
}

A more dynamic implementation that always adds class active to the current day’s div:

var today = new Date();
var dayOfMonth = today.getDate();

$('on-' + dayOfMonth).addClass('active');

If you have different numbered classes for each day (say you want every day to have a different color):

var today = new Date();
var dayOfMonth = today.getDate();

$('on-' + dayOfMonth).addClass('active-' + dayOfMonth); //Will add the class active-17 on the 17th day of each month, for example

1

solved How do I add class using jquery/javascript to different elements depending on what day is it?