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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:49:02+00:00 2026-05-30T01:49:02+00:00

I have a carousel slider, which have three static dots in the corner, one

  • 0

I have a carousel slider, which have three static “dots” in the corner, one for each slide.
When the slide is active, the corresponding dot is white. When inactive, the dot is grey.
I have made this possible with this code below, but Im new to Jquery so Im looking if this can be shortened.

Is it possible to rewrite this code to be shorter?

I have this in the HTML:

<a id="th_1" class="thumb act"></a>
<a id="th_2" class="thumb"></a>
<a id="th_3" class="thumb"> </a>

Then I have this in jquery, at the top of the document:

$(document).ready(function(){   

            $('#th_1').click(function(){
                $('#carousel').carousel(0); //go to slide1
                $('#th_1').addClass('act');
                $('#th_2').removeClass('act');
                $('#th_3').removeClass('act');
            ;})     

            $('#th_2').click(function(){
                $('#carousel').carousel(1); //go to slide 2
                $('#th_1').removeClass('act');
                $('#th_2').addClass('act');
                $('#th_3').removeClass('act');
            ;}) 

            $('#th_3').click(function(){
                $('#carousel').carousel(2); //go to slide 3
                $('#th_1').removeClass('act');
                $('#th_2').removeClass('act');
                $('#th_3').addClass('act');
            ;})

Then, I also have this below code for when the slides are rotating themselves, without clicks (because I need to change the dots when this happens as well).

$('#carousel_slide_1').hasClass('active')(function(){
                $('#th_1').addClass('act');
                $('#th_2').removeClass('act');
                $('#th_3').removeClass('act');
            });

$('#carousel_slide_2').hasClass('active')(function(){
                $('#th_1').removeClass('act');
                $('#th_2').addClass('act');
                $('#th_3').removeClass('act');
            });

$('#carousel_slide_3').hasClass('active')(function(){
                $('#th_1').removeClass('act');
                $('#th_2').removeClass('act');
                $('#th_3').addClass('act');
            });

The class “active” is on a div, which contains the slide. When the slide is active, this class is added through another carousel script to the div. So above I check if the div has this class, and if so, I change the class of the “dot”.

The class “act” is simply a background change of the “dot” which makes it white in color, if the class is set. If removed, color of dot is grey.

Hope I haven’t forgotten anything. If so, I will update this question.
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-30T01:49:02+00:00Added an answer on May 30, 2026 at 1:49 am

    For the first piece of code you can just use the index() function and a generic class like thumb as you have.

    $('.thumb').click(function(){
        $('#carousel').carousel($(this).index());
        $('.thumb').removeClass('act');
        $(this).addClass('act');
    });
    

    The second piece of code doesn’t seem right for what you’re trying to do. The idea is to create a function or object to handle these events where you can pass values and the you just call those functions within the jQuery event. I hope this makes sense.
    I wrote a tutorial a while ago on how to create a slider in jQuery, it might be useful.
    http://www.onextrapixel.com/2011/07/01/how-to-create-a-slideshow-plugin-with-jquery/

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

Sidebar

Related Questions

I am currently developing a site and have a need for a javascript-based carousel/slider
I have this jQuery carousel going: http://dougie.thewestharbour.com/wp-content/themes/dougie/slider.html It works pretty well right now but
have a custom made slider which I would like to stop on hover. I've
I currently have a jQuery Slider in progress: http://jsfiddle.net/hQj8a/ $(document).ready(function() { $('body').removeClass('no-js'); $('#my-carousel-2').carousel({ itemsPerPage:
I have a Carousel (jcarousel) which displays items inline. When loading, the items first
I have a project where users can interact with a carousel like slide show,
I currently have a carousel using Twitter's bootstrap on my website. I'm controlling which
I have a JQuery carousel which I have adapted for my needs. I need
I'm trying to have a slide carousel for displaying different plots in my website.
Have just started using Visual Studio Professional's built-in unit testing features, which as I

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.