views:

141

answers:

1

Hello!

I have a datepicker (jquery)

$("#datepicker").datepicker({

});

I want to colorize(highlight) some days in this datepicker. And these days i'd like to get from some array !!!!

I dont know, something like this:

$("#datepicker").datepicker({
highlight:['09/16/2009', 09/12/2009, 08/16/2009 ....] });

Help me please

Thanks a lot !!!

+2  A: 

Try using the beforeShowDay function of the datepicker. This fires before rendering each day in the picker. Inside the funcion you check if the current date is in an array of special dates. If it is then you can return an array where the second element is the name of the css class you want rendered on each td.

Demo here

  var someSpecialdates = [1, 5, 12, 21, 27, 30]; 

    $("#datepicker").datepicker({ 
      beforeShowDay: function(dt) { 
        var d = dt.getDate(); 
        return ( $.inArray(d, someSpecialdates ) === -1 ) ? [true,""] :
                                                            [true, "specialDateCSSClass"]; 
      }
    });
redsquare
So how would you go about highlighting, say, christmas?
Eric
well I would hold the month/day in the array and instead of checking just the day part I would also check the month
redsquare
See the answer here which shows exactly this http://stackoverflow.com/questions/501943/can-the-jquery-ui-datepicker-be-made-to-disable-saturdays-and-sundays-and-holida/503082#503082
redsquare