My jQuery function takes in the current month
. I would like to display the next and previous months depending on the buttons clicked.
My question is, is there a default
Date()
function I can call to know the next and previous months of a current month ?
$(document).ready(function () {
var current_date = $('#cal-current-month').html();
//current_date will have September 2013
$('#previous-month').onclick(function(){
// Do something to get the previous month
});
$('#next-month').onclick(function(){
// Do something to get the previous month
});
});
I can write some code and get the next and previous months, but I was wondering if there is any already defined functions
for this purpose?
SOLVED
var current_date = $('.now').html();
var now = new Date(current_date);
var months = new Array( January, February, March, April, May, June, July, August, September, October, November, December);
$('#previous-month').click(function(){
var past = now.setMonth(now.getMonth() -1);
$('.now').html(months[now.getMonth()]+' '+now.getFullYear());
});
$('#next-month').click(function(){
var future = now.setMonth(now.getMonth() +1);
$('.now').html(months[now.getMonth()]+' '+now.getFullYear());
});