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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:25:55+00:00 2026-05-27T20:25:55+00:00

I need help collapsing a collapsible div on page load. I’m using this JavaScript

  • 0

I need help collapsing a collapsible div on page load.

I’m using this JavaScript code:

<script type="text/javascript">
    function switchMenu(obj) {
        var el = document.getElementById(obj);
        if ( el.style.display != "none" ) {
            el.style.display = 'none';
        }
        else {
            el.style.display = '';
        }
    }
    document.getElementById('aboutme').style.display = 'none';
</script>

to collapse HTML div id=”aboutme” when the <a ...>about me</a> is clicked:

<div class="container">
    <a href="#" onclick="switchMenu('aboutme');">about me</a>
    <div id="aboutme">
        sample text to be expanded and collapsed
    </div>
</div>

I can’t get the page to close my div#aboutme on page load.

I want this page to load with my div collapsed.

I thought that the JS line

document.getElementById('aboutme').style.display = 'none';

should do the trick but it doesn’t. What am I doing wrong?

Thanks for your help.

  • 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-27T20:25:55+00:00Added an answer on May 27, 2026 at 8:25 pm

    If you want your div to load collapsed, simply write the following

     <div id="aboutme" style="display:none">
            sample text to be expanded and collapsed
        </div>
    

    This should resolve the problem.
    However, if you are still interested in the JavaScript solution keep reading.
    As you said I can't get the page to close my div#aboutme on page load – the problem is that you are not using “onload” event.
    Simply put the line document.getElementById('aboutme').style.display = 'none'; in your body’s onload attribute..
    something like this

    <body onload="document.getElementById('aboutme').style.display = 'none';">
    ...
    </body>
    

    and you should see the results with JavaScript. I recommend you use “style” method instead. much better.

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

Sidebar

Related Questions

Need help writing a script downloads data from google insight using c# this is
I need help on this following aspx code aspx Code: <asp:Label ID =lblName runat
i need help with disk_total_space function.. i have this on my code <?php $sql=select
I need help with debugging this piece of code. I know the problem is
Need help compiling in C. When using GCC at home (Windows, 3.4.5), the code
I need help with this route map routes.MapRoute(Blog_Archive, Blog/Archive/{year}/{month}/{day}, new { controller = Blog,
I need help refactoring this multi-loop thing. Here is what I have: Campaign has_many
Need help with reading special characters within my VB code. ASCII code Char(34) =
Need help with technical-designing of a website. I have a main page with a
Need help with this error. Can't see what's wrong. Error: Warning: mysql_query() expects parameter

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.