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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:03:23+00:00 2026-05-27T08:03:23+00:00

I’ve been trying to load up a DIV by default (dpara) and then allow

  • 0

I’ve been trying to load up a DIV by default (dpara) and then allow the user to switch through DIVs depending on the button they press.

On page load – dpara is visible but dtab and ddl are not.

If the user picks dtab for example, dpara is hidden, dtab becomes visible and ddl remains hidden.

But this doesn’t seem to be working since I’ve updated my code from this:

<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'>
        123
    </div>

    <div id='dtab'>
        456
    </div>

    <div id='ddl'>
        789
    </div>

In addition to this var visibleDiv is mean to store the id of the div I’m passing through – but on alert it returns [object HTTPInputElement]. Is there a few steps I’ve missed? Here is mu new code below:

    <script type='text/javascript'>
var visibleDiv;

function arrange(div) {
    // Cache the passed in 'div' as the currently visible one
    visibleDiv = div;

    alert(visibleDiv);

    // 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';
}
    </script>
    <form>
        <input type='button' value='dpara' onclick='arrange(this);' />
        <input type='button' value='dtab' onclick='arrange(this);' />
        <input type='button' value='ddl' onclick='arrange(this);' />
    </form>
    <div id='dpara'>123
    </div>

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

    <div id='ddl' style='display: none'>789
    </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-27T08:03:24+00:00Added an answer on May 27, 2026 at 8:03 am

    Try this updated version:

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

    JS Fiddle demo.

    The problems were that you were passing the DOM node into the function, while you needed the value from that node. To get around this you could have used: onclick="arrange(this.value);" or, as I’ve chosen to do, pass the DOM node into the function, and then find the value within the function.

    Secondly you were assuming that the JavaScript would find the right div element without invoking the document.getElementById() method, which I’ve corrected, assigning the the DOM node returned by document.getElementById(div.value) to the variable visibleDiv. I’ve also removed the alert(). But that wasn’t a problem, just to make it look a little better.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to loop through a bunch of documents I have to put
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I need to clean up various Word 'smart' characters in user input, including but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.