This question has already been answered:
It is a little confusing with this code - why is the figure 5 displayed inside the squares, not the consecutive 0..4?
There is a version:
- the cycle is run much faster, and until the first setTimeout is executed, the counter has already reached the maximum value.
$(function() { for (var i = 0; i < 5; i++) { setTimeout(function() { $('.rows').append('<div>' + i + '</div>'); }, 800 * i); $('.res').text($('.res').text() + " " + i); } }); .rows > div { width: 50px; height: 50px; background-color: #3c3; margin: 5px; float: left; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="rows"> <div></div> </div> <div class="res"></div>