Reputation: 14731
I have the following code for Jquery UI Datepicker
. How can I disable dates which are specific to certain days in a week?
i.e. I would like to display only days from today's date and would like to enable only
Monday and Friday
in a week, rest of the days should be disabled.
Markup:
<input id="datepicker" type="text">
Code
$(function () {
var date1 = new Date;
date1.setHours(0, 0, 0, 0);
date1.setDate(10);
var date2 = new Date;
date2.setHours(0, 0, 0, 0);
date2.setDate(23);
$("#datepicker").datepicker({
beforeShowDay: function (date) {
return [date < date1 || date > date2, ""];
}
});
});
Upvotes: 1
Views: 389
Reputation: 130
Give the specific day number in beforeshowday function
$(function() {
$("#datepic").datepicker(
{ beforeShowDay: function(day) {
var day = day.getDay();
if (day == 2 || day == 5) {
return [false, "somecssclass"]
} else {
return [true, "someothercssclass"]
}
}
});
});
Upvotes: 1