Reputation: 2277
I want after each times click value 2011
an increasing number, how is it?
$('button').click(function() {
var num = '2011';
var out = num ++1;
alert(num); // i want this output: 2012
});
Upvotes: 1
Views: 746
Reputation: 5555
var num = '2011';
$('button').click(function() {
num++;
alert(num); // i want this output: 2012
});
Upvotes: 3
Reputation:
Try this:
var num = '2011';
$('button').click(function() {
var out = num++;
alert(num);
});
var num
must be outside of the function, otherwise it will be 2011 again every time the function is run.num++1
should be num++
.Upvotes: 2
Reputation: 23786
var num = 2011;
$('button').click(function() {
num++;
alert(num); // i want this output: 2012
});
Upvotes: 4