$ (This ). find ('Article. loading '). each (function (I) {var El = This; setTimeout (function () {$ (EL ). replacewith ($ ('# dumpster article: First') ;}, speed );});
The preceding method only executes timeout once, and does not implement the expected latency of every each loop.
The correct method:
(1 ):
VaR elements = $ (this ). find ('Article. loading '); var Index = 0; setTimeout (function () {$ (elements ). get (index ). replacewith ($ ('# dumpster article: First'); index ++;}, speed );
Or
(2)
VaR speed = 1000; // init timer and stores it's identifier so it can be unset latervar timer = setinterval (replacearticle, speed); var articles = $ ('Article. loading '); var length = articles. length; var Index = 0; function replacearticle () {articles. eq (index ). replacewith ($ ('# dumpster article: First'); index ++; // remove timer after interating through all articles if (index> = length) {clearinterval (timer );}}