php - Loop through array of DIV ids, and refresh those DIVS every x seconds -
say have 4 divs:
<div id='blue'></div> <div id='refresh12'></div> <div id='red'></div> <div id='refresh23'></div>
i'm putting every div on page begins 'refresh' array this:
var divs = $('div[id^="refresh"]');
now, want do, refresh divs in array every 5 seconds. know need use setinterval, i'm not sure how start loop. also, divs aren't pulling content page, it's same page, dynamic data needs refresh every 5 seconds. appreciated. thanks.
using setinterval
not best idea, because if operation takes long , blocking, calls might stack up.
you can use settimeout()
calls achieve want:
var divs = $('div[id^="refresh"]'); settimeout(function refreshthem () { //code refresh divs divs.xy(); settimeout(refreshthem, 5000); }, 5000);
or if want first refresh run @ once:
(function refreshthem () { //code refresh divs divs.xy(); settimeout(refreshthem, 5000); })();
basically when refresh finished, new timeout set run same code again in 5 seconds.
Comments
Post a Comment