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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:54:38+00:00 2026-06-09T19:54:38+00:00

I have two buttons and two hidden divs containing different information. I’m trying to

  • 0

I have two buttons and two hidden divs containing different information. I’m trying to work out how to make the content appear when one button is clicked (I’ve managed to get this working fine) and then if the other button is clicked, the old div hides again and the new one opens.

Essentially:

Click here for content A! Click here for content B!

When user clicks content A, content A appears.
When user clicks content A again, content A disappears.

When user clicks content B, content B appears.

User can also toggle. E.g have content A div open, click content B button and content B is then loaded but content A closes itself.

Here is the JS I’m using:

function ShowDiv() {
document.getElementById("myDiv").style.display = "";
}

function ShowDiv2() {
    document.getElementById("myDiv2").style.display = "";
    }

HTML

<input type="button" name="answer" onclick="ShowDiv()" />
<input type="button" name="answer2" onclick="ShowDiv2()" />

<div id="myDiv" style="display: none;">Hi I'm content a!</div>
<div id="myDiv2" style="display: none;">Hi I'm content B!</div>

At the moment both buttons display content correctly, but when you try to click the other nothing happens.

  • 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-06-09T19:54:40+00:00Added an answer on June 9, 2026 at 7:54 pm

    If you want a toggle functionality, it’s just simply changing display from “” to “none” and back:

    function ShowDiv() {
        document.getElementById("myDiv").style.display = "";
        document.getElementById("myDiv2").style.display = "none";
    }
    
    function ShowDiv2() {
        document.getElementById("myDiv2").style.display = "";
        document.getElementById("myDiv").style.display = "none";
    }
    

    Though I’d highly recommend using jquery library and it’s toggle function.

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

Sidebar

Related Questions

I have hidden Divs with .display-link classes that are two levels up from an
I'm trying to have multiple UIImageView 's each with two buttons - A Take
I have two buttons and two divs(I put one above another). I made info
I have a view that has two buttons(First and Second) and one hidden field.
I have two buttons on a page that trigger two functions that make two
I have a form with two buttons. The first is hidden using Javascript. When
I have two hidden radio buttons and one visible button. Clicking this button should
I have two buttons that moves a movieclip up/down the Y-axis. How do I
I have two buttons, one for start recording and another for stop recording. i
I have two buttons, which the user can click and will open a FileDiagloag

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.