Jquery - Variable Increment +1
I've had a look round and I'm a little confused. There seems to be several responses to my particular problem but I don't fully understand. So if anybody could help that'd be grea
Solution 1:
var counter = 1;
setInterval(function() {
var _text = counter + "<br>";
$("div").append(_text);
counter++;
},5000);
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><div></div>
If you want it to replace the old number use .html()
instead of .append()
"01"
is a string, 1
is a number you can increment.
Solution 2:
If you just need zero padding:
functionpad(num, size) {
var s = num+"";
while (s.length < size) s = "0" + s;
return s;
}
var thumbNumber = "02";
thumbNumber = parseInt(thumbNumber);
var nextNumber = pad(++thumbNumber,2);
console.log(nextNumber);
Live Demo -- http://jsfiddle.net/v02vgw6w/2/
Post a Comment for "Jquery - Variable Increment +1"