1

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 Answers 2

3

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"]; 
      }
    }); 
Sign up to request clarification or add additional context in comments.

3 Comments

So how would you go about highlighting, say, christmas?
well I would hold the month/day in the array and instead of checking just the day part I would also check the month
See the answer here which shows exactly this stackoverflow.com/questions/501943/…
0

Here is the simple one, may be useful for someone

<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>

  <script>
  $(document).ready(function() {
    $("#datepicker").datepicker();
  });
  </script>

<form>
    <input id="datepicker" />
</form>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.