I use an endless loop of a each() with setInterval and setTimeout in this way:
var links = [];
links = ['zuinfos-1-tab', 'zuinfos-2-tab', 'zuinfos-3-tab', 'allgemein-tab'];
var init = 5000
var z = 0;
var n = new Date().getTime()
setInterval(function() {
$(links).each(function(index, value) {
setTimeout(function() {
$('a#' + value).trigger('click');
var j = new Date().getTime()
var diff = j - n
console.log(z + '\t' + index + '\t' + value + '\t' + diff);
}, 5000 * index)
});
z++;
}, init * 4)
All is fine, but the first setInterval comes too late. I have to set it to init * 4, because there are four elements in each-loop. At the beginning it should start with init * 1.
I tried with a counter like this:
}, z==1?init:init*4 )
But this does not work.