I'm currently trying to circle around JavaScript.
What I want is the text that will be printed on the screen and then counted to the given number, for example:
"Test"
[1 sec pause]
"1"
[1 sec pause]
"2"
[1 sec pause]
"3"
This is my JS:
$(document).ready(function() {
var initMessage = "Test";
var numberCount = 4;
function count(){
writeNumber = $("#target");
setTimeout(function(){
writeNumber.html(initMessage);
},1000);
for (var i=1; i < numberCount; i++) {
setTimeout(function(){
writeNumber.html(i.toString());
},1000+1000*i)};
};
count();
});
This is my markup:
<span id="target"></span>
When I create the page, all I get is a "Test" followed by a "4".
I am not a JavaScript genius, so the solution can be quite simple. Any hints of what's wrong are much appreciated.
You can play with my example here: http://jsfiddle.net/JSe3H/1/
timkl source
share