Loop through Weekdays array with JavaScript and add a class for today's 'date' -


i'm creating static looking calendar , want highlight today's column.

i'm looping through calendar rows, so:

var weekdays = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'] $('.calendar__row').each(function (index, value) {     $(this).append(weekdays[index]) }) 

when hits 'today' - want add class 'calendar__row' - how done?

i end with:

<div class="calendar__row">mon</div> <div class="calendar__row">tue</div> <div class="calendar__row">wed</div>...so on 

i'd add class on day we're on if that's possible! thank you.

you use getday function returns number 0 6 indicating current day of week (0 sunday, 1 monday, 2 tuesday, , on):

var today = new date().getday(); 

and based on check whether index matches in array , act accordingly class:

$('.calendar__row').each(function (index, value) {     $(this).append(weekdays[index]);      var today = new date().getday();         if (index == (today == 0 ? 6 : (today - 1))) {           $(this).addclass('today');      } }); 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -