Reputation: 107
How can I pass a variable from one click function to the other through JQuery?
$(document).ready(function() {
var n = 1;
$('#Next').click(function() {
var nn = n++;
});
$('#Previous').click(function() {
alert(nn);
});
});
Upvotes: 0
Views: 413
Reputation: 318352
As you already have a variable in a higher scope, use that, otherwise data()
would be a better approach.
$(document).ready(function() {
var n = 1;
$('#Next').click(function() {
n++;
});
$('#Previous').click(function() {
alert(n);
});
});
Upvotes: 1