Search code examples
javascriptjquerydatepicker

jQuery Datepicker BeforeShowDay Second Parameter


jQuery's datepicker allows you to highlight dates using the BeforeShowDay callback.

Is it possible to pass a second parameter to the method?

$(selector).datepicker({beforeShowDay: selectedDay});   

function selectedDay(date) {

    // Do stuff

    return [true, 'class_name'];
}

As you can see, the parameter date is automatically passed to the selectedDay method, thus making me unsure as to how to pass a second parameter.

Cheers.


Solution

  • function selectedDay(date, param ) {
         // Do stuff with param
         return [true, ''];
    }
    
    function doStuff(){
        var param = "param_to_pass";
        $(selector).datepicker({
            beforeShowDay: function (date){
                return selectedDay(date, param );
            }
        }); 
    }