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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:29:23+00:00 2026-06-15T23:29:23+00:00

I have a variable that contains HTML code of a bunch of items. I

  • 0

I have a variable that contains HTML code of a bunch of items. I would like to append all these items in two second intervals. The code I have written below appends all of the items at once. I do not understand why it is doing this as the setTimeout() is within the each().

var myVar = "<div class='item'>Item01</div>" +
            "<div class='item'>Item02</div>" +
            "<div class='item'>Item03</div>";

$(myVar).each( function() {
    var value = $(this);
    setTimeout( function {
        $('.item-list').append(value);
    }, 2000);
}
  • 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-15T23:29:24+00:00Added an answer on June 15, 2026 at 11:29 pm

    Try this:

    var myVar = "<div class='item'>Item01</div>" +
                "<div class='item'>Item02</div>" +
                "<div class='item'>Item03</div>";
    
    $(myVar).each( function(index) {
        var value = $(this);
        setTimeout( function() {
            $('.item-list').append(value);
        }, 2000 * (index + 1));
    };
    

    Explanation

    In your original code, the loop occurs very quickly. Let’s pretend each iteration of the loop takes 1ms. That means that the first item is added 2001ms later, the second item 2002ms later, and the third one 2003ms later.

    By getting the index of the item in the array, we can add the first item 2000ms later, the second one 4000ms later, and so on.

    Update: Fixed syntax error.

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

Sidebar

Related Questions

I have a variable ( $page ) that contains HTML code as follows: <html>
I have a variable that contains the entire html for a page as a
I have got a Html and Javascript code, that contains about 1000 lines and
I have an HTML form that contains the following code: <input id=image_22 name=images[] type=file
I have a string variable that contains the following html data: <p> <em><strong>This is
I have a txt variable that contains my html string that I need to
I have an html file that contains the following code : <select id=gouv name=gouv>
I have the following variable which contains the following string. I would like to
I have trouble with replacing certain values in a variable that contains captured html.
I have a html page that contains a structure like this: <table class=pick> <tr>

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.