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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:47:14+00:00 2026-05-13T15:47:14+00:00

I’m trying to create a simple animation. Long story short, I’ve got a list

  • 0

I’m trying to create a simple animation. Long story short, I’ve got a list of 20 small divs and one outside div. I want to display five small divs within a large div at the time. Ideally, I would get a set of next 5 divs every 5 seconds.
I’m using jquery ajax function to create small divs, here’s the code:

$(document).ready(function(){
        var amount=0;
         $.ajax({
             type: "GET",
             url: "SampleServiceIncidentList.xml",
             dataType: "xml",
             success: function(xml){

                            //creates divs within GadgetMain div, works fine.

                                      });
                            amount = $("#gadgetMain").children().size(); //counts how many small divs there are
                            $("#testText").append("amount of children:"+amount); //and displays it in a test field
                            divideFeed();
             }//close success
         }); //close $.ajax(


        function divideFeed(){  //divides the set of small divs into groups 
            var limit = 5;
            var pagesNo = Math.ceil((amount/limit));
            var minimum=0; 
            var maximum;
            var i=0;
            while (i<pagesNo)
            {               
                minimum= i*limit;
                maximum=minimum+limit;                  


                //
                // PROBLEM HERE
                //
                populate(minimum, maximum);

                i++;
            }                   
        }

        function populate(minimum, maximum){
            $("#gadgetMain div").addClass('hidden'); //hides all small divs
            $("#testText").append('<br/>min: '+minimum+' max: '+maximum); //prints current group of divs (0-5; 5-10 etc)
            $("#gadgetMain div").slice(minimum,maximum).removeClass('hidden');  
            }

});

So, the problem is that I can’t get it to wait 5 seconds to display a group of divs I’m interested in. I know that it divides divs correctly – when I alert the minimum and maximum value, it changes the content of the outer div everytime I close the alert.
But I can’t find a way of pausing the function.

I would be very grateful for some help, it’s driving me mad

  • 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-05-13T15:47:15+00:00Added an answer on May 13, 2026 at 3:47 pm

    You don’t want to pause the function; instead, you want to hand control back to the browser and have it call you back after an interval. The window.setTimeout function does that. (There’s also the related window.setInterval, but I usually prefer setTimeout.)

    It requires a bit of mental logic inversion, but it’s very like making an Ajax call — you ask for something, then let go and have the browser call you back when you get it.

    So for instance:

    function doSomething(x) {
    
        runner();
    
        function runner() {
            console.log("x = " + x);
            --x;
            if (x > 0) {
                window.setTimeout(runner, 1000);
            }
        }
    }
    
    doSomething(10);
    

    …counts down from 10, once per second. doSomething returns almost immediately, but then runner gets called back once a second until it stops rescheduling itself.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have just tried to save a simple *.rtf file with some websites and
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.