Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9201051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:54:43+00:00 2026-06-17T22:54:43+00:00

I have 25 elements on this page: <div id=test1></div> <div id=test2></div> <div id=test3></div> <div

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:54:44+00:00Added an answer on June 17, 2026 at 10:54 pm

    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 :

    var test = {};
    setInterval(function() {
        $('div[id^="test"]').each(function(i, ele) {
            (function(idx) {
                $.post("./main/", {
                    record: idx,
                    opt:'get_res'
                }, function(data){
                    test[idx] = data;
                });
            })(i+1);
        });
    }, 15000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this html page which globally exists of div , section , and
I have written a HTML page which has following code. <div id=adsListContainer style=margin: 5px;>
I have following HTML code: <div id=wrapper> <div class=page id=first> Test<br/> Test<br/> Test<br/> Test<br/>
I have a page consisting of many elements with alphanumeric ids such as this:
I have this code: class LFSeq: # lazy infinite sequence with new elements from
I have written this code to join ArrayList elements: Can it be optimized more?
Suppose i have this structure of elements: <div class=parent> <div class=something1> <div class=something2> <div
I currently have: <div id=thumbImages> <ul> <li><img src=thumbimages/test1.jpg alt=thumb1 width=125 height=100 /></li> <li><img src=thumbimages/test2.jpg
Let's imagine that I have something like this: <html> ... <div> <iframe src=test.html hash=r4d5f7></iframe>
In my page I have severals divs. When the user hovers over 1 div

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.