Search code examples
jqueryjquery-uijquery-ui-datepicker

JQuery Datepicker - only select mondays and thursdays


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,""]}

Solution

  • 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.