Highlight specific dates in jQuery UI Datepicker

I read other questions like this one here, but no one is doing exactly what I want.

I want to add a class all days between two dates. Dates will be set in variables.

Any thoughts?

+3
source share
1 answer

You need to implement the beforeShowDay event for datepicker :

The function accepts the date as a parameter and should return an array with [0] equal to true / false, indicating whether this date is selectable, [1] equal to the name (s) of the CSS class or '' default presentation and [2] additional pop-up tooltip for this date. it is called for every day in the datepicker before displaying it.

, - :

$("#datepicker").datepicker({
    beforeShowDay: function(d) {
        var a = new Date(2012, 3, 10); // April 10, 2012
        var b = new Date(2012, 3, 20); // April 20, 2012
        return [true, a <= d && d <= b ? "my-class" : ""];
    }
});

jsFiddle demo here .

+9

All Articles