JQuery Datepicker - only select mondays and thursdays

Tom picture Tom · Sep 27, 2010 · Viewed 18.1k times · Source

I have the following code which only allows users to select Mondays from jquery datepicker.

I want to adapt this to be able to select mondays and thursdays.

Any ideas?

beforeShowDay: function(date){ return [date.getDay() == 1,""]}

Answer

Nick Craver picture Nick Craver · Sep 27, 2010

You can add an or (||) in there, like this:

beforeShowDay: function(date){ 
  var day = date.getDay(); 
  return [day == 1 || day == 4,""];
}

This only incurs the cost of .getDay() once per date shown, not that it's an expensive operation anyway, but no reason not to be efficient.