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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:17:57+00:00 2026-05-27T10:17:57+00:00

jQuery beginner here. I’m working on a site with with two links. Each link

  • 0

jQuery beginner here.

I’m working on a site with with two links. Each link slides out content a div with content below. The problem I’m having is that I can’t figure out how to toggle between both when the user clicks the other link.

So when the user clicks LINK-A it slides out CONTENT-A, while CONTENT-A is showing if the user clicks LINK-B CONTENT-A should slide back before CONTENT-B slides out.

Hope this makes sense, really hope someone can help me!

  • 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-27T10:17:57+00:00Added an answer on May 27, 2026 at 10:17 am

    HTML–

    <a href="#" id="link-a">Link A</a> - <a href="#" id="link-b">Link B</a>
    <div id="container">
        <div id="content-a">Content A</div>
        <div id="content-b">Content B</div>
    </div>
    

    CSS–

    Each content div is absolutely positioned inside of the container div so it can be animated in and out of view:

    #container {
        position : relative;
        width    : 500px;
        height   : 200px;
    }
    #content-a {
        position   : absolute;
        top        : 0;
        left       : 0;
        width      : 100%;
        height     : 100%;
        background : red;
    }
    #content-b {
        position   : absolute;
        top        : 0;
        left       : -100%;
        width      : 100%;
        height     : 100%;
        background : green;
    }
    

    JS–

    //cache the content area selectors since they will be used multiple times
    var $content_a = $('#content-a'),
        $content_b = $('#content-b');
    
    $('#link-a').on('click', function () {
    
        //when the `a` link is clicked, animate `b` content off-screen
        $content_b.stop().animate({
            left : '-100%'
        }, 500, function () {
    
            //then animate the `a` content on-screen after the `b` content's animation completes
            $content_a.stop().animate({
                left : 0
            }, 500);
        });
    });
    
    //then do the same (but in reverse) for the `b` link
    $('#link-b').on('click', function () {
        $content_a.stop().animate({
            left : '-100%'
        }, 500, function () {
            $content_b.stop().animate({
                left : 0
            }, 500);
        });
    });
    

    Here is a demo: http://jsfiddle.net/4eN84/

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

Sidebar

Related Questions

jQuery beginner here. Here is what I'm working on. I have an area map
Beginner question here. I'm going to make a Jquery function that is used to
please can you help a jquery beginner out? I don't really know how to
i m a beginner... here i m using the jquery for showing search results
i m a beginner... i have added two different jQuery... one is pop up
first time posting here. I'm a beginner in jquery and i ran into some
First, I'm pretty beginner of jQuery or AJAX. I've got around 50+ links on
I'm a javascript/jquery beginner. I'm trying to gray out, disable, and change the background
I'm a jQuery beginner. I'm adding a bunch of new images into a div.
I'm just starting to get into jquery/javascript programming so this may be a beginner

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.