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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:21:15+00:00 2026-05-23T23:21:15+00:00

There are 3 div s and 3 links. Only one div should be displayed

  • 0

There are 3 divs and 3 links.

Only one div should be displayed at a time. When user clicks on a link for one of the other divs, the current one should fade out and the selected one should fade in, in place of the previous div.

Here is the code at the moment:

Javascript

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        switches = $('#switches > li');
        slides = $('#slides > div');
        switches.each(function(idx) {
                $(this).data('slide', slides.eq(idx));
            }).click(
            function() {
                switches.removeClass('active');
                slides.removeClass('active').fadeOut('slow');
                $(this).addClass('active');
                $(this).data('slide').addClass('active').fadeIn('slow');
            });
    });
</script>

CSS

    <style style="text/css">
        ul {
            list-style: none;
        }
        li:hover {
            text-decoration: underline;
        }

        #switches .active {
          font-weight: bold;
        }

        #slides div {
          display: none;
        }

        #slides div.active {
          display: block;
        }

        .outer {
            position: absolute;
        }
        .outer div {
            width: 600px;
            height: 300px;
        }
        #uno {
            background-color: red;
        }
        #dos {
            background-color: blue;
        }
        #tres {
            background-color: green;
        }
    </style>

HTML

    <ul id="switches">
        <li class="active">First slide</li>
        <li>Second slide</li>
        <li>Third slide</li>
    </ul>

    <div class="outer" id="slides">
        <div class="active" id="uno">
            First div.
        </div>
        <div id="dos">
            Second div.
        </div>
        <div id="tres">
            Third div.
        </div>
    </div>

You can view the page here:
http://dl.dropbox.com/u/6920023/proofOfConcept.html

I’m attempting to use standard Jquery to do this, but clearly there is something wrong with my javascript code.

Can you spot what’s wrong and how to fix it?

  • 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-23T23:21:16+00:00Added an answer on May 23, 2026 at 11:21 pm

    Your CSS defines a div that’s not active as hidden. So as soon as you remove the active class, it will be hidden immediately.

    So, remove this entry:

        #slides div {
          display: none;
        }
    

    And add something like this on page load:

    $(function() {
        $('#slides div:not([class="active"])').hide();
    }); // will hide inactive slides initially but not always
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is div named dvUsers. there is an anchor tag lnkUsers. When one clicks
How to center a div across all browsers and behind this div there should
I currently have three Divs and only one of them is in focus at
Firstly, there have some tag links in my main page. click each one, post
I have a container (div) with a background image. In this div there is
There is a div that has inner content, a div with a border that's
In my webpage, there's a div with a class named Test . How can
In the main gadget html, there is a div with an onclick that calls
I want to center a background image. There is no div used, this is
There's a HTML: <div class=test> <ul> <li>Item 1</li> <li>Item 2</li> </ul> </div> And a

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.