I have 25 elements on this page:
<div id="test1"></div>
<div id="test2"></div>
<div id="test3"></div>
<div id="test4"></div>
<div id="test5"></div>
Also I have code for update html in divs:
setInterval(function() {
$.post("./main/", {
record:1,
opt:'get_res'
}, function(data){
$test1=data;
});
}, 15000);
To change the html in all the blocks I need to run this code 5 times, ex:
setInterval(function() {
$.post("./main/", {
record:1,
opt:'get_res'
}, function(data){
$test1=data;
});
}, 15000);
setInterval(function() {
$.post("./main/", {
record:2,
opt:'get_res'
}, function(data){
$test2=data;
});
}, 15000);
.....
.....
setInterval(function() {
$.post("./main/", {
record:3,
opt:'get_res'
}, function(data){
$test3=data;
});
}, 15000);
For example for 25 elements div need write this code 25 times – it will be been very big code.
Tell me please whether implementation of the code in a loop, so as not to repeat it several times?
Just iterate over the elements somehow, use the index or extract the number from the ID, and store in an array or object, whatever fits best :