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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:30:08+00:00 2026-05-25T09:30:08+00:00

I started building a testimonial rotator for a project. Oddly enough it broke before

  • 0

I started building a testimonial rotator for a project. Oddly enough it broke before it made it live (tested it prior) and I decided to scrap it and write a new script to perform the same task. I’m relatively new to jQuery and I’m not the most familiar with using ternary operators but I wanted to give that a shot.

The code below is what I’m working with. It’s my belief that this code should execute properly however if you were to copy the entirety of it into a new .html doc you’ll see it doesn’t.

I’m looking for any help I can get. I’m always trying to grow as a developer – I’m not one to just copy and paste blindly to get a result. I like to know what’s going on 🙂

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <title>Rotator Testing</title>

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>

    <style type="text/css">
        #testimonials{
            width:300px;
            height:100px;
            background:#666;
            position:absolute;
            top:0;left:0;
        }
        .testimonial{
            color:#CCC;
            display:block;
            width:200px;
            height:30px;
            background:#333;
            position:absolute;
            left:0;top:0;
            z-index:5;
        }
        .show{
            z-index:10;
        }
    </style>

    <script type="text/javascript">
        $(document).ready(function(){
            $('.testimonial').css({opacity: 0.0});
            $('.testimonial:first').css({opacity:1.0});
            setInterval(function(){

                var current = ( $('#testimonials .testimonial.show')? $('#testimonials .testimonial.show') : $('#testimonials .testimonial:first'));
                var next = current.next().length ? $('#testimonials .testimonial:first') : current.next();

                //Set the fade in effect for the next testimonial, show class has higher z-index
                next.css({opacity: 0.0})
                .addClass('show')
                .animate({opacity: 1.0}, 1000);

                //Hide the current testimonial
                current.animate({opacity: 0.0}, 1000)
                .removeClass('show');


            },2000);
        });
    </script>



</head>

<body>

    <div id="testimonials">
        <article class="testimonial">Testimonial 1</article>
        <article class="testimonial">Testimonial 2</article>
        <article class="testimonial">Testimonial 3</article>
        <article class="testimonial">Testimonial 4</article>
    </div>

</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-25T09:30:08+00:00Added an answer on May 25, 2026 at 9:30 am
    var current = ( $('#testimonials .testimonial.show')? $('#testimonials .testimonial.show') : $('#testimonials .testimonial:first'));
    

    jQuery will always return an object(even if the selector doesn’t match any element), so your condition:

    $('#testimonials .testimonial.show')
    

    …will always be true.

    Check the length instead:

       var current = ( $('#testimonials .testimonial.show').length)
                        ? $('#testimonials .testimonial.show') 
                        : $('#testimonials .testimonial:first');
    

    the next issue:

    var next = current.next().length ? $('#testimonials .testimonial:first') : current.next();
    

    I guess you need to switch this to:

    var next = (!current.next().length) 
                ? $('#testimonials .testimonial:first') 
                : current.next();
    

    Currently you select the .next() if it is empty.

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

Sidebar

Related Questions

I'm getting started on building a REST API for a project I'm working on,
I am a java beginner and for my first project I started building a
just started building out a rails project from scratch after months of re-purposing of
I've just started building a prototype application in Django. I started out by working
I recently started building a console version of a web application. I copied my
I'm getting started building a site with Rails and I would like people to
Hi I started building apps with this technology and I am facing a weird
I recently started looking into building web applications using .NET MVC and I stumbled
I am building an app to learn Django and have started with a Contact
This build warning just started showing up. I'm building for 3.1.3. Not sure what

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.