I have been trying to fix this script for more than an hour and still can't get it to work. It is a loop performing animate and html jquery events in a setInterval.
Here is the fiddle: http://jsfiddle.net/GNrL3/
Here is the code (same as fiddle but some prefer to have it here):
$(document).ready(function() {
var i = 1;
var startinterval = 0;
$('#clickhere').click(function() {
startinterval = setInterval("curvalues()", 1000);
});
function curvalues() {
if ($i == 20) {
clearInterval(startinterval);
}
else {
$("#square").animate({
"left": "+=30px"
}, "slow");
$("#text").html("Barracks");
$i++;
}
}
});
<div id="square" style="position:absolute;height:30px;width:30px;background-color:#F07014;"></div>
<br /><br /><br /><br /><br />
<div id="text" style="height:30px;width:100px;border:1px solid #000">Text box</div>
<br /><br />
<input type="button" value="Start" id="clickhere"/>
My belief is that the issue concerns the setInterval of the function, but still, the syntax seems good to me...