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

  • Home
  • SEARCH
  • 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 6729451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:17:31+00:00 2026-05-26T10:17:31+00:00

I have an array and all I want to do is when the page

  • 0

I have an array and all I want to do is when the page is fully loaded a word (inside a span tag in the html) fade out with jQuery and replaced with a word from the array, show the new word for 2 seconds and be replaced again by the next word of the array until the array is over.
It’s so simply but I’ve tried a thousand different ways with loops and always go over the array before displaying anything on the website and when it is fully loaded shows me the last word of the array.

Here is one of my attemps:

$(function(){
    var words=new Array('red','blue','yellow','black','white','orange',
                        'green','brown');
    var wordList;
    for(var i in words){
        wordList=words[i];
        $("#word").fadeOut(200).html(wordList).fadeIn(200).delay(2000);
    }   
});

Probably the mistake is very silly but I’m starting with javascript and I’m going crazy… Thanks

  • 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-26T10:17:32+00:00Added an answer on May 26, 2026 at 10:17 am
    1. Use [] instead of new Array().
    2. .html is not an animation function and will run immediately (ignoring .delay), so it won’t go word by word. Set it only when the animation completes with the second argument you can pass to animation functions.
    3. You can use setTimeout to run a function after a certain amount of time. The problem you’ll encounter is scoping with a for loop (wordList will be the same each time). However, you can make use of $.each and pass a function (a function will introduce a new scope, and the scoping problem will go away).

    http://jsfiddle.net/pimvdb/EkaAF/

    $(function(){
        var words = ['red','blue','yellow','black','white','orange', 'green','brown'];
    
        $.each(words, function(i, v) { // for each word (i is index, v is value)
            setTimeout(function() {
                $("#word").fadeOut(200, function() { // fade out
                    $(this).html(v).fadeIn(200); // when completed, set html and fade in
                });
            }, i * 2000); // 2000 * index, so each one will wait 2000 ms after previous one
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of strings: @array I want to concatenate all strings beginning
I have an array of array like below with all numeric values. I want
I have an array of threads, and I want to Join them all with
Specifically, I have an array of strings called val, and want to replace all
I have a an array of observable collections and I want to display all
I have loaded a table of data into an HTML page so that it
I have an array of values all well within the range 0 - 63,
You have: val array = new Array[Array[Cell]](height, width) How do you initialize all elements
I have a 3D array in Python and I need to iterate over all
Imagine you have a large array of floating point numbers, of all kinds 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.