jquery - Moving through JavaScript objects and increment by one on each click? -
i trying move next month on click of div have months store objects in months = []; when use ++ repeats same month why? heres js:
var newdate = new date(); var getnewmonthword = newdate.getmonth(); var = 0; months = []; months[0] = ('january'); months[1] = ('february'); months[2] = ('march'); months[3] = ('apri'); months[4] = ('may'); months[5] = ('june'); months[6] = ('july'); months[7] = ('august'); months[8] = ('september'); months[9] = ('october'); months[10] = ('november'); months[11] = ('december'); var countemonth = getnewmonthword; var mymonthname = months[countemonth]; $('#test span').replacewith('<span>' + mymonthname + '</span>') $('#addone').on('click', function () { alert('fred'); countemonth++; //months[++i]; // $('#test span').replacewith('<span>' + countemonth + '</span>') $('#test span').replacewith('<span>' + mymonthname + '</span>') });
if uncomment countemonth replacewith ad 1 each returns number not name...
update mymonthname
on every click , this:
$('#addone').on('click', function () { countemonth = ((countemonth+1) % months.length); mymonthname = months[countemonth]; $('#test span').replacewith('<span>' + mymonthname + '</span>') });
Comments
Post a Comment