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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:49:15+00:00 2026-05-25T06:49:15+00:00

I am curious if it is possible to achieve a simple div swap using

  • 0

I am curious if it is possible to achieve a simple div swap using only css if the div does not have a fixed height. I have searched far and wide for an answer and have come up with little solid discussion on the matter.

The idea is to have an expansive beer list divided into four separate divs and to display only one of them at a time. When clicking a corresponding anchor, the div displayed would switch while hiding the other three. The first div should display when the page loads. I have a little experience with this and have had success but only with fixed sizes as the foremost div would hide all other divs behind it.

These particular divs will contain formatted tables and unordered-lists. I am not sure if that will have any affect, but thought it was worth mentioning just in case. The divs cannot have a fixed height because the number of items in each will vary. I haven’t yet coded it as I am not sure if it is worth the time investment but the HTML would look something like this:

<div id="secondaryNav">      
  <ul>
    <li>Link to div1</li>
    <li>Link to div2</li>
    <li>Link to div3</li>
    <li>Link to div4</li>
  </ul>
</div>

<div id="swappedContent">
  <div id="1">
    <table>
      <tr>content</tr> x 40-50
    </table>
  </div>
  <div id="2">
    <table>
      <tr>content</tr> x 40-50
    </table>
  </div>
  <div id="3">
    <table>
      <tr>content</tr> x 40-50
    </table>
  </div>
  <div id="4">
    <table>
      <tr>content</tr> x 40-50
    </table>
  </div>
</div><!--swappedContent-->

I found an example that I am modeling this layout after (that uses javascript) but I am not sure of the appropriateness of linking to a site which I do not own here. If I should link to it for clarity, please let me know.

  • 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-25T06:49:15+00:00Added an answer on May 25, 2026 at 6:49 am

    Trying using the CSS “display”. In each div do:

    <div id="myDiv" style="display:none;">
    

    And then when you want to display the div, do the following in JavaScript:

    document.getElementById("myDiv").style.display = "block";
    

    So in the end, you’d have something like:

    <div id="secondaryNav">      
        <a href="javascript:void(0)" onclick="showDiv('1')">Link to div1</a>
        <a href="javascript:void(0)" onclick="showDiv('2')">Link to div2</a>
        <a href="javascript:void(0)" onclick="showDiv('3')">Link to div3</a>
        <a href="javascript:void(0)" onclick="showDiv('4')">Link to div4</a>
    </div>
    
    <div id="swappedContent">
      <div id="1">
        <table>
          <tr>content</tr> x 40-50
        </table>
      </div>
      <div id="2" style="display:none;">
        <table>
          <tr>content</tr> x 40-50
        </table>
      </div>
      <div id="3" style="display:none;">
        <table>
          <tr>content</tr> x 40-50
        </table>
      </div>
      <div id="4" style="display:none;">
        <table>
          <tr>content</tr> x 40-50
        </table>
      </div>
    </div>
    
    <script type="text/javascript">
    function showDiv(divId) {
        for (i = 1; i <= 4; i++) {
            document.getElementById(i).style.display = "none";
        }
    
        document.getElementById(divId).style.display = "block";
    }
    </script>
    

    Note: be sure to put the script in an appropriate place (usually in the element).

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

Sidebar

Related Questions

I'm curious whether this is possible, or as I suspect, by design not. In
Just curious, is it possible to write a multi-platform program that is not writen
I am curious it is possible to create a window without using WndProc. So
I do not think this is possible and curious if it is or why
I am curious if this is possible with Mercurial. I'd like to have a
I'm curious is it possible to change text properties of tick labels independently of
Still wrapping my head around Delegates and I'm curious: Is it possible to overload
Just curious here: is it possible to invoke a Windows Blue Screen of Death
I'm curious if this is even possible.
I'm curious if this is possible at all since a select * from html

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.