jQuery datepicker get month and year shown not current
datepicker, javascript, jquery
Solution
`$.datepicker('getDate')` only returns the selected date of the datepicker, not the month that is currently being shown.
What you're looking for is to bind a function to `onChangeMonthYear`. Docs here
Example:
$('#calendar').datepicker('option', 'onChangeMonthYear', function(year, month) { var selectedMonth = month })
Problem
I'm trying to get the "shown" month and year after hitting the "next" and "previous" links on the left and right of the date picker header. Currently I'm using to get the month: ``` var selectedMonth = $('#calendar').datepicker('getDate').getMonth() + 1; ``` but it only returns the current month, not the shown month that comes with clicking "next" or "prev". EDIT I added the `onChangeMonthYear` option with the datepicker in the function i have ``` function getDates() { var selectedMonth = $('.ui-datepicker-month').text(); var selectedYear = $('.ui-datepicker-year').text(); } ``` still this just states the current date. EDITED Again the above worked just needed to set a delay :]