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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:51:01+00:00 2026-05-26T08:51:01+00:00

This is my first time building a loop in jQuery or js, and I’ve

  • 0

This is my first time building a loop in jQuery or js, and I’ve gotten myself over my head.

I have a piece of content that needs to loop on page load:

<li id="nav_about"><a href="">Loren ipsum <span id="adjective">1</span></a>
</li>

At a regular interval to go down the following functions (swapping text out), and then once the loop reaches the last function, to return to the top and start it all over again.

{$("#adjective").fadeOut(500).delay(100).text("2").fadeIn(500);}
{$("#adjective").fadeOut(500).delay(100).text("3").fadeIn(500);}
{$("#adjective").fadeOut(500).delay(100).text("4").fadeIn(500);}
{$("#adjective").fadeOut(500).delay(100).text("1").fadeIn(500);}

I know I need to use setInterval, define a variable, and create a function here somehow, but honestly I’m lost as to how the pieces go together.

My gut level guess is that even this is a rather clunky way of achieving this, and there’s likely a method of defining the .text terms as variables in an array as to avoid the multiple .fadeOuts and .fadeIns.

Could sure use some help here.

  • 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-26T08:51:02+00:00Added an answer on May 26, 2026 at 8:51 am

    You are not doing this correctly. You don’t want setInterval here.

    The first thing you need to know is that the way your wrote it, all of these command will run simultaneously meaning you will be fading in and out at the same time (which is going to look odd). When you chain command they don’t wait – they all run at the same time. Instead you use the callback feature, when each animation is done it calls the callback which does the next step.

    Change it to this:

    function fader(text, next) {
      $("#adjective").fadeOut(500, function() {
        $(this).text(text).delay(100).fadeIn(500, function() {
          next();
        });
      });
    }
    
    function fader2() { fader('2', fader3); }
    function fader3() { fader('3', fader4); }
    function fader4() { fader('4', fader1); }
    function fader1() { fader('1', fader2); }
    
    fader2();
    

    The fader function does each step of the animation. Then when the final animation is done it calls the function passed in as next to continue the loop.

    Then I setup a bunch of functions to define the sequence (I’m sure there are other ways to do this – an array perhaps, but this was the first that came to mind).

    PS. I didn’t test this, there may be typos.

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

Sidebar

Related Questions

This is my first time attempting to call an ASP.NET page method from jQuery.
This is my first time with Web services. I have to develop web services
this is my first time posting here, I have a question which I have
This is my first time building a website and using CodeIgniter for a school
This is my first time building an authenticated API and I'm running into a
This is my first time building a database with a table containing 10 million
This is my first time building a UI in Access (using Access 2007), and
This is my first time I need to create a cutscene system. I have
This is my first time using joomla. I don't know if I'm using the
This is my first time on StackOverflow though I read Coding Horror quite often.

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.