I’m using the following code to delay a trigger looping through a list of li items
var eleID = '';
$('.SlideSelect').each(function(i) {
eleID = $(this).attr('id');
$('#'+eleID).delay(800*i).trigger('click');
});
However the delay does not work and just loops through.
Does anyone know why?
var eleID = '';
$('.SlideSelect').each(function() {
eleID = $(this).attr('id');
setTimeout(function(){
$('#'+eleID).trigger('click');
}, 5000)
});
Delay is used for the animation queue. If you want to delay anything else, you should use setTimeout. Note the use of a separate function to allow the capture of each value in the delayed function.