I have a website that has an expanding widget area in the topbar above the header. You can see this here: http://khill.mhostiuckproductions.com/siteLSSBoilerPlate/
When clicking the arrow to expand this area, you can see that it switches to a different button that faces the opposite direction. When clicking it a second time to bring this area back up, the arrow doesn't switch back to it's original position.
I have tried many things pertaining to the class switching topic here at SO but I could not get any of it to work. Change an element's class with JavaScript
How do I best switch the class on this button from expand-arrow to collapse-arrow with the code I already have below? To that extent, should I simply drop the code below and use something easier/better?
CSS:
.collapse-arrow {
display: inline-block;
width: 24px;
height: 24px;
background: url('../../../images/collapse-arrow.png');
}
.expand-arrow {
display: inline-block;
width: 24px;
height: 24px;
margin-top: 5px;
background: url('../../../images/expand-arrow.png');
}
Javascript
<script language="javascript"><!-- THIS IS THE SLDING TOP BAR -->
(function() {
var open = false;
toggle = function() {
var ele = document.getElementById("toggleText");
var text = document.getElementById("displayText");
ele.style.height = (open ? 0 : ele.scrollHeight)+"px";
document.getElementById("displayText").className =
document.getElementById("displayText").className.replace
( /(?:^|\s)expand-arrow(?!\S)/g , '' );
open = !open;
}
})();
</script>
HTML:
Button:
<a class="expand-arrow" id="displayText" href="javascript:toggle();"></a>