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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:19:26+00:00 2026-05-14T03:19:26+00:00

how can i use jQuery to show/hide the same div area… essentially swapping out

  • 0

how can i use jQuery to show/hide the same div area… essentially swapping out content?

here is what i have so far, and i cant figure out how to hide the previous content and replace it with the new content:

       <script type="text/javascript">
    $(document).ready(function(){

    $('.content').hide();

    $('a').click(function(){
    $('.content').show('slow');
    });

    //then hide previous content

    });

    </script>

<a href="#" id="a-link">A</a>
<a href="#" id="b-link">B</a>

  <div class="start-content" id="a">
  content here
  </div>

  <div class="content" id="b">
  content here
  </div>
  • 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-14T03:19:26+00:00Added an answer on May 14, 2026 at 3:19 am

    If you wrap the contents in a div, this would be a bit easier, like this:

    <div id="wrap">
      <div class="start-content" id="a">
      content here
      </div>
    
      <div class="content" id="b">
      content here
      </div>
    </div>
    

    And this in jQuery:

    $('a').click(function(){
      $("#wrap > div").hide(); //hide previous
      $('.content').show('slow'); //show what's clicked on
    });
    

    Since you have a convention with your IDs though, you can use that, either give you links a class, or wrap them as well, like this:

    <div id="links">
      <a href="#" id="a-link">A</a>
      <a href="#" id="b-link">B</a>
    </div>
    <div id="wrap">
      <div class="start-content" id="a">
      content here
      </div>    
      <div class="content" id="b">
      content here
      </div>
    </div>
    

    Then you could use a single event handler for all your links like this:

    $('#wap > div:not(.start-content)').hide(); //Initial hide
    $("#links a").click(function() {
      $("#wrap > div").hide(); //hide previous
      var id = $(this).attr("id").replace('-link', ''); //matching id
      $('#' + id).show('slow'); //show what's clicked on
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this example http://jsfiddle.net/HnfCU/ I use jQuery to show and hide the .child
Possible Duplicate: How can I use delay() with show() and hide() in Jquery How
How can I use jQuery to be able to show or hide a specific
How can I use jquery to remove a SPECIFIC div that has no children
I have an image $(#main) how can I use jquery to dosomething(this) when the
I have a blob of HTML. How can I use jQuery to remove the
I have a document with headings and unordered lists. How can I use JQuery
I can't seem to use jQuery Accordions with definition lists that have multiple desciption
I am trying to use jQuery to show a div when the user clicks
Hi I have been trying to make a show/hide toggle button with jquery but

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.