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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:15:58+00:00 2026-05-27T07:15:58+00:00

I am working with 3 divs at the moment – on pageLoad the default

  • 0

I am working with 3 divs at the moment – on pageLoad the default is viewed but when the user clicks on a button the div is hidden and the selected div appears in its place.

How would I write an if statement to identify the div currently selected by the user? For example:

if selected_div is 'dpara' then ....

else if selected_div is dtab then ....

Thanks in advance!

    <script type='text/javascript'>
        function arrange(div_id) {
            // First make all the divs hidden...
            divs = document.getElementsByTagName('div');
            for( var i = 0; i < divs.length; i++ ) {
                divs[i].style.display = 'none';
            }

            // Now make the one we want to be visible visible...
            document.getElementById(div_id).style.display = 'block';
        }
    </script>
    <form>
        <input type='button' value='dpara' onclick='arrange(this.value);' />
        <input type='button' value='dtab' onclick='arrange(this.value);' />
        <input type='button' value='ddl' onclick='arrange(this.value);' />
    </form>
    <div id='dpara'>
    </div>

    <div id='dtab' style='display: none'>
    </div>

    <div id='ddl' style='display: none'>
    </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-27T07:15:59+00:00Added an answer on May 27, 2026 at 7:15 am

    As you’re already going through a function for each button click you could just keep the visible div in a variable, something like:

    var visibleDiv;
    
    function arrange(divId) {
        // Cache the passed in 'div' as the currently visible one
        visibleDiv = document.getElementById(divId);
    
        // First make all the divs hidden...
        var divs = document.getElementsByTagName('div'),
            i,
            len;
    
        for (i = 0, len = divs.length; i < len; i++) {
            divs[i].style.display = 'none';
        }
    
        // Now make the one we want to be visible visible...
        visibleDiv.style.display = 'block';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code below working for only first div. I can't display other divs when
I'm working on a jquery based homepage with 5 or so hidden divs, each
I have a page I am working with that has several hidden DIVs that
I'm working on a div (parent) that has two other divs (menu and content)
Trying to create collapsible / expandable divs using jQuery, but it's not working for
I am working with a dashboard of divs and each div it has a
I am working on a site laid out with div s. I am having
I'm working on a page has an ol with nested p's, div's, and li's.
Working on a project at the moment and we have to implement soft deletion
I am working on a site that is based on CSS and DIVs Unfortunately

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.