0

i would like to get delay of 3 seconds between appending of each rows

Only first iteration of append works, rest of the array is not printed

$(document).ready(function(){
var n=[];
for(var i=1;i<80;i++)
{
n[i]=i;
$("#content table").append("<tr><td>"+n+"<td></tr>").setTimeout(3000);
}
});
violet kiwi
  • 695
  • 2
  • 10
  • 19
  • `delay()` doesn't work like this.. it works for functions like `animate` or you have to build up a queue.. You have to use `setTimeout()`instead.. – Anujith Jan 28 '13 at 11:57
  • http://stackoverflow.com/questions/8401308/jquery-delay-function – Th0rndike Jan 28 '13 at 11:57

2 Answers2

1

Try:

 $(document).ready(function () {
 var n = [];
  for (var i = 1; i < 80; i++) {
      n[i] = i;
      $("#content table").delay(3000)
          .queue(function (nxt) {
          $(this).append("<tr><td>" + n + "<td></tr>");
          nxt(); 
      });
   }
 });

Sample

Anujith
  • 9,370
  • 6
  • 33
  • 48
0

Here is a working example: http://jsbin.com/etaqez/4/edit

I've used a setInterval backed with a counter. If it reaches the length of the array the interval is cleared.

$(document).ready(function(){
  var n=[];
  for(var i=1;i<80;i++) {
    n[i]=i;
  }

  var counter = 1;

  var addRow = function(elem){
    if (counter < n.length) {
      $("#content table").append("<tr><td>"+n[counter]+"<td></tr>");

      counter += 1;      
    } else {
      clearInterval(timer);
    }
  };

  var timer = setInterval(addRow, 3000);  

});
Jo David
  • 1,696
  • 2
  • 18
  • 20