Enable weekends in jQuery Datepicker

In my previous post "Disable Weekends in jQuery DatePicker", I had shown you that how can you disable the weekends in jQuery Datepicker control. However, there could be a situation where you need to enable only weekends and disable all the other days. See below image.

 

Below given small piece of code fulfill our requirement.

$(function()
{
    $('#txtDate1').datepicker({ beforeShowDay:
      function(dt)
      {
        return [dt.getDay() == 0 || dt.getDay() == 6, ""];
      }
   });
});

When you run this code, you will see the only weekends are enabled. beforeShowDay option, which takes a function to be called for each date, returning true if the date is allowed or false if it is not.

See live Demo and Code.

Feel free to contact me for any help related to jQuery. I will gladly help you.