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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:48:55+00:00 2026-06-11T17:48:55+00:00

I have a div that expands on a click, but I can’t work out

  • 0

I have a div that expands on a click, but I can’t work out how to set it to be un-expanded when the page is closed?

        <script>
     function toggleDiv(id1,id2) {
      var tag = document.getElementById(id1).style;
      var tagicon = document.getElementById(id2);

      if(tag.display == "none") {
       tag.display = "block";
       tagicon.innerHTML = "&nbsp;-&nbsp;";
      } else {
       tag.display = "none";
       tagicon.innerHTML = "&nbsp;+&nbsp;";
      }
     }
</script>

And the HTML:

<div class="title" onClick="javascript:toggleDiv('content1','icon1');">
     <span style="float:left">Options</span>
     <span id="icon1" style="float:right">&nbsp;-&nbsp;</span> 
    </div>
    <div id="content1" class="item">
     <div><input type="button" onclick="changeBG('#FF0097')" value="Magenta"/></div>
     <div><input type="button" onclick="changeBG('#A200FF ')"  value="Purple"/></div>
     <div><input type="button" onclick="changeBG('#00ABA9')"  value="Teal"/></div>
     <div><input type="button" onclick="changeBG('#8CBF26')"  value="Lime"/></div>
     <div><input type="button" onclick="changeBG('#F09609')" value="Orange"/></div>
     <div><input type="button" onclick="changeBG('#1BA1E2')"  value="Blue"/></div>
     <div><input type="button" onclick="changeBG('#E51400')"  value="Red"/></div>
     <div><input type="button" onclick="changeBG('#339933')"  value="Green"/></div>
    </div>

The CSS incase you need it:

.title {
      padding:5px; 
      border:1px solid #CCCCCC;
      font:15px arial; 
      width:100px; 
      cursor:pointer;
      height:20px;
     }

     .item {
      padding:5px; 
      border:1px solid #CCCCCC; 
      font:12px verdana; 
      width:100px;
     }

     .item div {
      border-bottom:1px solid #CCCCCC;
      padding:5px;
     }

     .button {
      border:1px solid #CCCCCC; 
      padding:5px;
      cursor: pointer;
     }

As you can see the drop down menu lets the user change the background color of the website. I was wondering if it would be possible to create a cookie to store the change so it doesn’t default to white background first until the user selects a color?

Thank you Stack Overflow (:

All and any help is appreciated.

  • 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-11T17:48:56+00:00Added an answer on June 11, 2026 at 5:48 pm

    I am sure there is a body on your html page. just add a function like stated below. It works. I’ve tested

    <body onLoad="toggleDiv('content1','icon1')">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey there, i have a div that expands when the page is loaded, now
I have a button set up that when clicked, expands the page. Here is
I have a div that expands to the height of it's content. It works
I have a div that I click on to drag it. Once it's on
I need to change this script so that I can click on my slideshow-expand
I want to have a table that the user can expand/contract the contents (but
I have a working toggle function that expands and collapses but my list when
I have created some JQuery that will expand a div 'popup' on hover and
I have a div that will serve as container to other element, I have
I have a div that contains a list of messages (it's a chatroom application).

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.