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

The Archive Base Latest Questions

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

I posted a question up yesterday that asked for some help on an image

  • 0

I posted a question up yesterday that asked for some help on an image switching script I had written, thank you to all that helped me. I’ve extended the script and have run into a problem that I can’t for the life of me spot where the problem is.

HTML:

<div id="feature-image">
    <h1><span>A random heading</span></h1>
</div>

<div id="feature-links">
    <a class="a1" href="#">1</a>
    <a class="a2" href="#">2</a>
    <a class="a3" href="#">3</a>
</div>

JS + Jquery:

$(function(){
    $('#feature-links a').click(function() {

        if ($(this).hasClass('a-active')) {
            return false;
        } else {

    var image = $(this).attr('class');

        switchToImg(image, function() {
            $('#feature-links a .a-active').removeClass('a-active'); 
            $('#feature-links .' + image).addClass('a-active');
        });
    }
});

function switchToImg(image){
    $('#feature-image').fadeOut('300', function(){
        $('#feature-image').css('background-image','url(images/main_' + image + '.jpg)');
        $('#feature-image').fadeIn('300');
    });     
};              

In the script I check for a click on an <a> tag, each <a> tag has a class of (a1, a2, a3 etc.). Also, the active <a> has a class of ‘a-active’.

I’m attempting to check if a-active is set with this:

if ($(this).hasClass('a-active')) {
    return false;
}

and cut the script there so that it doesn’t fade in and out the same image. However, the image continues to fade in and out despite my return false on checking for the class a-active and returning false. I am sure the problem is in the section where I am using .addClass and .removeClass but my knowledge of Javascript and Jquery is to flaky for me to properly debug this.

Could someone cast a critical eye over this please?

Thanks in advance.

  • 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-26T10:01:48+00:00Added an answer on May 26, 2026 at 10:01 am

    You have incorrectly passed an anonymous function to your switchToImg() function, which doesn’t accept one.

    Instead, try the following JS:

    $(function() {
        $('#feature-links a').click(function() {
    
            if ($(this).hasClass('a-active')) {
                return false;
            } else {
                var image = $(this).attr('class');
    
                switchToImg(image);
            }
        });
    
        function switchToImg(image) {
            $('#feature-image').fadeOut('300', function() {
                $('#feature-image').css('background-image', 'url(images/main_' + image + '.jpg)');
                $('#feature-image').fadeIn('300');
            });
            $('#feature-links a.a-active').removeClass('a-active');
            $('#feature-links .' + image).addClass('a-active');
        };
    });
    

    Tested in jsFiddle.

    EDIT: I removed the call to .stop(), it wasn’t necessary and introduced a bug.

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

Sidebar

Related Questions

Yesterday, I posted an answer to a question that included several (unknown to me
Yesterday, I posted a question on some tips doing this Remote Client-Server Application in
I posted a question yesterday regarding issues that I was having with my backpropagating
I've posted a question yesterday but I just realized that the answer doesn't seem
I posted this question yesterday and the answer I go mentioned that I should
As a result of some helpful answers to a question I posted yesterday about
I all. I posted yesterday a question regarding dates not sent with jquery-ajax and
So I posted a question yesterday about placing some divs within a container so
Similar to the question I posted yesterday , I have this problem that I
I posted the following question yesterday: Multiple 'in' statements in a where clause that

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.