jQuery UI Datepicker: Disable Specific Days

Nov 26, 2012
Introduction
  
In this
jQuery UI Datepicker article I will explain how to disable specific days in jQuery datepicker.
Description:
  
In previous posts I explained
Disable specific dates in Calendar, Disable Future dates in Calendar, Disable weekends in datepicker, Show multiple months in datepicker and many articles relating to JQuery and datepicker. Now I will explain how to disable specific days in jQuery datepicker.

To disable specific days in datepicker we need to write the code like as shown below
$(function() {
$("#datepicker").datepicker({ beforeShowDay: function(date) {
var day = date.getDay();
return [(day != 1 && day != 3)];
}
});
});
If you want to see it in complete example needs to write below code in your page
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>jQuery Datepicker: Disable Particular Dates</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<script type="text/javascript">
$(function() {
$("#datepicker").datepicker({ beforeShowDay: function(date) {
var day = date.getDay();
return [(day != 1 && day != 3)];
}
});
});
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker" /></p>
</body>
</html>
Demo

Comments