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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:32:22+00:00 2026-06-14T08:32:22+00:00

I want two buttons, that are oppositely shown or hidden when clicked. (i.e., via

  • 0

I want two buttons, that are oppositely shown or hidden when clicked. (i.e., via style:display=none|block;).

Initially, button1 would be display:block and button2 would be display:none.

When you click button1, it would switch button2 to be display:block and button1 to be display:none.

I know this is probably somthing so simple, please excuse my lack of knowledge.

  • 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-14T08:32:23+00:00Added an answer on June 14, 2026 at 8:32 am

    First we create two buttons. Give them id attributes so we have an alias by which to access them:

    <button id="first">Click</button> <button id="second">Second</button>
    

    Set the CSS as you defined:

    #first  { display: block; }
    #second { display: none;  }
    

    Then comes the JS. We access both elements through their IDs using a function called document.getElementById(). This will return the element with the specified ID.

    var first = document.getElementById( 'first' ),
        second = document.getElementById( 'second' );
    

    And now we can make a toggle function. Here is the concept: If the display attribute of the first element is “block”, then we change it to “none” and we change the latter to “block”. And vice-versa. Here it is:

    function toggle() {
    
        if ( first.style.display === "block" ) {
    
            first.style.display = "none";
            second.style.display = "block";
    
        } else { // switch back
    
            first.style.display = "block";
            second.style.display = "none";
    
        }
    
    }
    

    Then we set the event handlers in the HTML thusly:

    <button id="first" onclick="toggle();">First</button>
    <button id="second" onclick="toggle();">Second</button>
    

    or we can do it using JS:

    first.onclick = toggle;
    second.onclick = toggle;
    

    I like the second better, we’ll stick with that,

    And there you have it. You can find a working example here — http://jsfiddle.net/twEK5/

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

Sidebar

Related Questions

i want to create a form that has two submit buttons, but each one
I want to create a view that contains two forms with their submit buttons.
I am a newbie to Android programming. I want two radio buttons that when
I want to realize some mobile layout with two divs or buttons that fill
Its just that. I want to center two buttons. My toolbar looks like this
I have two buttons in my program and i want that when i press
I have two TextBoxes with corresponding two Buttons. I want that when a TextBox
I want to extend the WPF Combobox in a way that two buttons are
I have a html file that has two buttons, approve and reject. I want
I have two array and three button in segment control i want that when

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.