Im trying to add a class to a each element in a collection. I want add a classs to the elemnt then wait a sec or two then add the class to the next one in the collection.
But when I use this code it just adds the class to each one at once.
for (var i = 0; i < article.length; i++) {
setTimeout(function () {
$(article[i]).addClass('something';
}, 10000);
}
The problem is that you are setting a bunch of timeouts 10 seconds from the same moment in time, so they will all execute 10 seconds later at once. You need to chain them together so that each timeout handler invokes the next timeout: