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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:13:05+00:00 2026-06-15T15:13:05+00:00

(New at jQuery) Trying to write a function that moves an active class along

  • 0

(New at jQuery)

Trying to write a function that moves an active class along as an arrow is clicked..

html

<div id="steps">
    <a href="#1" data-ref="dynamic-tabs slider-id">
        <div class="step step-1 active">
            <div class="step-img">
                <img width="175" height="120" src="http://site.com/img.png">
            </div>
            <div class="step-title">Schedule Online or Wave Down a Biker</div>
            <div class="step-over"></div>
         </div>
      </a>

     <a href="#2" data-ref="dynamic-tabs slider-id">
         <div class="step step-2">
             <div class="step-img">
                 <img width="175" height="120" src="http://site.com/img.png">
             </div>
             <div class="step-title">We Bike to & Clean Your Car</div>
             <div class="step-over"></div>
         </div>
     </a>

     <a href="#3" data-ref="dynamic-tabs slider-id">
         <div class="step step-3">
             <div class="step-img">
                 <img width="175" height="120" src="http://site.com/img.png">
             </div>
             <div class="step-title">Come Back to a Clean Car</div>
             <div class="step-over"></div>
         </div>
     </a>
 </div>

<div class="nav-right" data-dir="next" title="Slide right">
    <a href="#">right »</a>
</div>

jQuery I’m trying

$(".nav-right a").click(function() {
    if( $(".step-1").is('.active') ) {
      $(".step-1").removeClass("active");
      $(".step-2").addClass("active");
    }
});

$(".nav-right a").click(function() {
    if( $(".step-2").is(".active") ) {
      $(".step-2").removeClass("active");
      $(".step-3").addClass("active");
    } 
});

$(".nav-right a").click(function() {
    if( $(".step-3").is(".active") ) {
      $(".step-3").removeClass("active");
      $(".step-1").addClass("active");
    } 
});
  • 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-15T15:13:06+00:00Added an answer on June 15, 2026 at 3:13 pm

    The problem seems to be that you create 3 (sic!) event handlers which fire sequentially when you click the link.

    1. The first handler, as step 1 is active, sets step 2 to active.
    2. The second handler, as step 2 is now active, sets step 3 to active
    3. The third handler, as step 3 is now active, sets step 1 to active again.

    In the end, nothing has happened.

    Solution: Use only one event handler, and if-else-statements instead of only if-statements:

    $(".nav-right a").click(function() {
        if( $(".step-1").is('.active') ) {
          $(".step-1").removeClass("active");
          $(".step-2").addClass("active");
        } else if( $(".step-2").is(".active") ) {
          $(".step-2").removeClass("active");
          $(".step-3").addClass("active");
        } else if( $(".step-3").is(".active") ) {
          $(".step-3").removeClass("active");
          $(".step-1").addClass("active");
        } 
    });
    

    Of course, we can do much better and write a generic function, which also does not need the step-N classes:

    var rotatedElements = $(".step");
    $(".nav-right a").click(function() {
        var cur = rotatedElements.filter(".active");
        cur.removeClass("active");
        var index = rotatedElements.index(cur) + 1;
        if (index >= rotatedElements.length)
            index = 0;
        rotatedElements.eq(index).addClass("active");
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a function in jQuery that will add a class to
I'm trying to write a function that in each call open a new window.
I'm fairly new to Javascript/JQuery. I'm trying to write an app that takes text
I've been trying to use the new jquery-ui, and all but the resizable function
I am new to jQuery and am trying to fire a function on a
I fairly new to JQuery and perhaps trying to achieve something that might be
I'm trying to write a recursive jQuery statement that grabs some data and populates
Hopefully just a quick question :) I'm trying to write little jQuery that will
For a JQuery plugin that I am trying to write I would like to
I'm fairly new to JavaScript and am trying to write some code that lists

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.