# Switch image on collapsed or expanded content. MUCH NEEDED HELP PLEASE!

**URL:** <https://forum.kirupa.com/t/switch-image-on-collapsed-or-expanded-content-much-needed-help-please/320074>\
**Category:** Uncategorized\
**Created:** [March 13, 2011, 3:06pm UTC](https://forum.kirupa.com/t/switch-image-on-collapsed-or-expanded-content-much-needed-help-please/320074 "2011-03-13T15:06:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sith717](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@Sith717](https://forum.kirupa.com/u/Sith717)\
**Post date:** [March 13, 2011, 3:06pm UTC](https://forum.kirupa.com/t/switch-image-on-collapsed-or-expanded-content-much-needed-help-please/320074/1 "2011-03-13T15:06:26Z")

</div>

Hey guys, Im creating a javascript content expander and would like to know how to create it so it changed the image from an down arrows to open the box, and a down arrow to close the box.

Here is my current code.

```auto
<script type="text/javascript">
//var persistmenu="yes"
var persisttype="sitewide" 

if (document.getElementById){
document.write('<style type="text/css">
')
document.write('.submenu{display: none;}
')
document.write('</style>
')
}

function SwitchMenu(obj){
    if(document.getElementById){
    var el = document.getElementById(obj);
    var ar = document.getElementById("masterdiv").getElementsByTagName("span"); 
        if(el.style.display != "block"){ 
            for (var i=0; i<ar.length; i++){
                if (ar*.className=="submenu")
                ar*.style.display = "none";
            }
            el.style.display = "block";
        }else{
            el.style.display = "none";
        }
    }
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function onloadfunction(){
if (persistmenu=="yes"){
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=get_cookie(cookiename)
if (cookievalue!="")
document.getElementById(cookievalue).style.display="block"
}
}
function savemenustate(){
var inc=1, blockid=""
while (document.getElementById("sub"+inc)){
if (document.getElementById("sub"+inc).style.display=="block"){
blockid="sub"+inc
break
}
inc++
}
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
document.cookie=cookiename+"="+cookievalue
}

if (window.addEventListener)
window.addEventListener("load", onloadfunction, false)
else if (window.attachEvent)
window.attachEvent("onload", onloadfunction)
else if (document.getElementById)
window.onload=onloadfunction

if (persistmenu=="yes" && document.getElementById)
window.onunload=savemenustate
</script>

<style type="text/css">
.sectionHeadernews .plaquenews {
 background: url(../layout/section_header_plaque_medium.png) center no-repeat;
}

.sectionHeadernews .plaquenews, .sectionHeaderchat .plaque_medium, .sectionHeaderchat .plaque_large {
 height: 26px;
 text-align:center
 overflow: hidden;
 line-height: 25px;
 font-size: 14px;
 font-family: Palatino Linotype, Book Antiqua, Palatino, Times New Roman, Times, serif;
 font-weight: bold;
 font-variant: small-caps;
 color: #30291f;
}

.sectionHeadernews {
 background: #bd9c5a url(../layout/section_header_bg.png) top repeat-x;
 width: 754px;
}

.sectionHeadernews .leftnews {
 background: url(../layout/section_header_left_news.png) left no-repeat;
}

.sectionHeadernews .rightnews {
 background: url(../layout/section_header_right_news.png) right no-repeat;
}
</style>

<div class="sectionHeadernews">
<div class="leftnews">
<div class="rightnews" onclick="SwitchMenu('sub1')" >
<div class="plaquenews">
Click to view current website news
</div>
</div>
</div>
</div>

```

I want the \<div class=“rightnews”\> thing to change from an up arrow to a down arrow.

Here are the icons im using.  
For the box to contract: ![](http://forum.kirupa.com/uploads/kirupa/6485/83de26cb7e3d92f4.png)

for the box to expand. ![](http://forum.kirupa.com/uploads/kirupa/6486/6753265ec5a50332.png)

If someone could help me out by adding the code so the images switch would be great!
