How to change jQuery datepicker number of months dynamically/responsive

Viewed 3063

I'm asking this question because I couldn't find an answer in another one. If there is please link it to me.

I have a jQuery Datepicker on which I set the parameter numberOfMonths: 2

I want it to be 1 if the screenSize goes below some number (eg 768px). I tried:

$(window).resize(function(){
    if($(window).width() < 768){
        $('#datepicker').datepicker({
            numberOfMonths: 1
        })
    }
}

But since the datepicker is already initialised it does not work.

What can I do?

2 Answers
Related