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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:40:51+00:00 2026-05-27T17:40:51+00:00

The code below successfully fades in one testimonial for 6 seconds, waits 3 seconds,

  • 0

The code below successfully fades in one testimonial for 6 seconds, waits 3 seconds, and then fades it out and moves on to the next. Once it reaches the third testimonial it jumps back to the first. This is exactly what I want but on my actual site I have more than three testimonials and in the future may be adding more. I don’t want to have to go back and add a new function every time I add a new testimonial. I tried for some time to get this to work using “this” and .next() but failed. I’m hoping someone could make this much more efficient by looping it and getting it to move to the next p tag within the container without calling a new function every time. Any help is appreciated, thank you.

Note: I know there are similar questions but none of them were quite the same and the answers are sub par.

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<style>
#tml-container p { display: none; }
</style>
</head>
<body>

<div id="tml-container">
    <p id="one">Testimonial 1</p>
    <p id="two">Testimonial 2</p>
    <p id="three">Testimonial 3</p>
</div>

<script>
$(document).ready(function() {
    function doFade() {
        $("#one").fadeIn(6000,function() {
            $("#one").fadeOut(6000).delay(3000);
            setTimeout(fadeTwo,6000);
        });
    }

    function fadeTwo() {
        $("#two").fadeIn(6000,function() {
            $("#two").fadeOut(6000).delay(3000);
            setTimeout(fadeThree,6000);
        });
    }

    function fadeThree() {
        $("#three").fadeIn(4000,function() {
            $("#three").fadeOut(6000).delay(3000);
            setTimeout(doFade,6000);
        });
    }
    doFade();
});
</script>

</body>
</html>
  • 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-27T17:40:52+00:00Added an answer on May 27, 2026 at 5:40 pm

    This is a very simple solution:

    function fade($ele) {
        $ele.fadeIn(6000).delay(3000).fadeOut(6000, function() {
            var $next = $(this).next('p');
            // if there is a following `p` element, it is faded in
            // otherwise start from the beginning by taking
            // the parent's first child
            fade($next.length > 0 ? $next : $(this).parent().children().first());
       });
    };  
    
    fade($('#tml-container > p').first());
    

    DEMO


    Reusable plugin version:

    Instead of iterating over the children of a certain element, it iterates over the selected elements.

    (function($) {
        var default_config = {
            fadeIn: 3000,
            stay: 3000,
            fadeOut: 3000
        };
    
        function fade(index, $elements, config) {
            $elements.eq(index)
              .fadeIn(config.fadeIn)
              .delay(config.stay)
              .fadeOut(config.fadeOut, function() {
                  fade((index + 1) % $elements.length, $elements, config);
              });
        }
    
        $.fn.fadeLoop = function(config) {     
            fade(0, this, $.extend({}, default_config, config));
            return this;
        };
    
    }(jQuery));
    

    Usable as:

    $('#tml-container > p').fadeLoop({fadeIn: 6000, stay: 3000, fadeOut: 6000});
    

    DEMO

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

Sidebar

Related Questions

The code below works. But if I comment out the line Dim objRequest As
I have successfully scheduled local notifications in my app using the code below: Class
I want to run the Java code below in Matlab. It ran successfully in
My code shown below will successfully return an array of values using print_r. How
The code below works insomuch that I can successfully download the directory recursively. But,
newbie here. I successfully created a chat server using c# (server partial code below,
I can build and execute the code below successfully : IplImage* img = cvLoadImage(C:\\hello.jpg);
I wrote the code below that successfully gets a random line from a file;
The code below successfully recognizes internal classes which are decorated with my custom Module
The code below successfully triggers the FB.api() function when the button named button2 is

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.