Jquery datepicker trigger after month change (after month)

I want to highlight a few days in the current month. I can do this in the first month, but not in the new month after clicking on "next month" or "previous month". I tried to use the onChangeMonthYear event, but this is done before the new (or previous) month appears.

any ideas?

+7
javascript jquery jquery-ui datepicker uidatepicker
source share
3 answers

Probably your best bet is a beforeShowDay .

http://jqueryui.com/demos/datepicker/#event-beforeShowDay

You can specify a new class name for the cell based on your date criteria.

+1
source share

You can do this with jQuery datepicker using the custom "renderCallback".

eg. This example disables the weekend and adds a styling class these days. There are many other complex examples that may also help ...

 $('.date-pick') .datePicker( { renderCallback:function($td, thisDate, month, year) { if (thisDate.isWeekend()) { $td.addClass('weekend'); $td.addClass('disabled'); } } } ); 

Also, if you prefer, the dpMonthChanged event will occur after re-displaying the calendar, and you can iterate over the contents of the calendar and make a selection ...

+1
source share
  hack: $('#calendar').datepicker({ onChangeMonthYear: function (year, month, inst) { setEventsDay() } }); function setEventsDay(){ var days = $(".ui-state-default"); console.log(days.length); //31 from august to Sep setTimeout(function () { var days = $(".ui-state-default"); console.log(days.length); //30 `enter code here`from august to Sep }, 100) } 
0
source share

All Articles