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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:23:23+00:00 2026-05-23T18:23:23+00:00

What is the best/recommended manner in which to insert a ‘pause’ with each enumeration

  • 0

What is the best/recommended manner in which to insert a ‘pause’ with each enumeration over a set of elements using the jQuery ‘.each()’?

$( '.someClass' ).each( function() {
    $( this ).trigger( 'click' ); //fire some request that appends a new div on the body 
    //wait for div to be appended to the DOM.  perhaps use the pause here
    //execute code once the div has been appended 
});
  • 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-23T18:23:23+00:00Added an answer on May 23, 2026 at 6:23 pm

    Technically, you can’t do this as you have modeled in your code, since JavaScript is single-threaded, and usually runs on the browser (or tab) UI thread — any sleep/delay will block the browser from redrawing the page and will also prevent user interaction with the page.

    You need to arrange for the browser to invoke your code periodically. Something like this will do the trick:

    var objects = $.makeArray($( '.someClass' ));
    
    var callback;
    
    callback = function() {
        var item = objects.shift();
    
        // Do something with item.
    
        if (objects.length != 0) {
            setTimeout(callback, 5000);
        }
    }
    
    setTimeout(callback, 5000);
    

    See an example.

    This solution assumes that you want each item to be processed 5 seconds from the time that the last item finished processing. This means that:

    1. If you do confirm() or something while processing each item, the next item will be processed 5 seconds from the time that the user closes the dialog.
    2. The total execution time will be (5000N + T) where N is the number of items in the initial list, and T is the total time it takes to process each item.

    Here’s a function you can use that encapsulates this functionality:

    jQuery.eachWithDelay = function(sequence, delay, callback) {
        var objects = jQuery.makeArray(sequence);
    
        if (objects.length == 0) {
            return;
        }
    
        var f;
    
        f = function() {
            var item = objects.shift();
    
            if (callback(item) && objects.length != 0) {
                setTimeout(f, delay);
            }
        };
    
        setTimeout(f, delay);
    };
    

    Called like:

    $.eachWithDelay($('.someClass'), 5000, function(item) {
        // Do something with item
    
        return true; // Return true to continue iterating, or false to stop.
    });
    

    See the updated fiddle.

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

Sidebar

Related Questions

Using ASP.net, is there a recommended best way to access a particular field of
Which is the best recommended algorithm to use for encrypting passwords in php/mysql
The recommended best practice is to set the current culture of the application's thread
What is the most recommended/best way to stop multiple instances of a setTimeout function
I understand that BigDecimal is recommended best practice for representing monetary values in Java.
What's the best/recommended way to copy data between a byte array and an integer
I have a C# windows service which listens to a MSMQ and sends each
What is the best and recommended practice regarding capitalization for naming controls in, for
What is the best way or recommended best practice in the flow of database
What is the best or recommended method for bit shifting a large amount of

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.