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 8528611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:50:28+00:00 2026-06-11T08:50:28+00:00

I have two functions function getImgStr(imgName){ thisStr = ‘<img src=/_shared/img/discovery/200×100/’+imgName+’.jpg>’; return thisStr; } function

  • 0

I have two functions

 function getImgStr(imgName){
        thisStr = '<img src="/_shared/img/discovery/200x100/'+imgName+'.jpg">';
        return thisStr;
    }
    function buildIt(imgSrc){
        console.log(imgSrc);
        $('#content').append('<div></div>');
        $('#content div:last').hide()
            .addClass('imgBox')
            .attr('id',imgSrc)
            .html(getImgStr(imgSrc))
            .slideDown(2000);
    }

I have an array that I am looping

$(function(){
        for(i=0;i<=imgList.length-1;i++){
                buildIt(imgList[i]);
        }
    });

works fine, no probelms.

But when I try to wrap this is a setInterval is barfs

$(function(){
        for(i=0;i<=imgList.length-1;i++){
            var loadIt = setInterval(function(){
                buildIt(imgList[i]);
            },1000);
        }
    });

the console.log in buildIt is undefined when the setInterval is there so I am assuming that the interval somehow affects the loop but I do not understand what I am doing wrong. Any ideas?

  • 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-11T08:50:29+00:00Added an answer on June 11, 2026 at 8:50 am

    Per your clarification: If you want to load images one after the other every second, you can do something like this. You don’t need a loop at all.

    var i = 0;
    var id = setInterval(function() {
        if(i === imgList.length) {
            clearInterval(id);
        } else {
            buildIt(imgList[i++]);
        }
    }, 1000)
    

    What this does is initialize the value of i to 0. i functions exactly like i in your for loop. It’s essentially an index. Then, you store the value of the interval inside the variable id. This way you maintain a reference to the interval so that you can clear it when you are done loading the images.

    Finally, inside the interval function you check to see if i is equal to the length of the number of images in your image list. If it is, we know that we’re done loading all of them so we clear the interval. Otherwise we call the buildIt function for the image that corresponds to the current value of i and the increment the value of i.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two functions here function Preloader() {} Preloader.prototype = { init:function() { //
So, I have two JavaScript functions: function Generate() { //Do something $.ajax({data:{Svc: 'cpMain', Cmd:
For example suppose I have the following two functions function a(param1) { console.log(param1); }
i have two functions, the parent function is __triggerAction, than child function is __triggerNormal
Say I have two functions that expect ...rest parameters private function a(...myParams):void { trace(myParams.length);
I have two functions in an ActionScript class, they are: private function loaderCompleteHandler(event:Event):void {
I have two functions hooked on the submit event of a form. Each function
I have two functions that return simple strings. Both are registered. $.views.helpers({ parseDate: function
I have two Python functions, both of which take variable arguments in their function
I have defined the following two functions test <- function(t) { return( (0.5*eta^2/theta)*(1-exp(-2*theta*t)) )

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.