Jump to content

Collapse & Expand Javascript Menu?


Solarpitch

Recommended Posts

You shouldn't need an image or glyph.

If the '+' is the [i]hot [/i] element, then it's likely in it's own div or span.
So you could replace the character in that div with [b].innerHTML()[/b] .

Make a function for show() and hide(),  but make a third for [b]toggle()[/b], so that you can use the same function for both actions.
Figured I'd mark this up for you.
I didn't need a show()/hide() after all ; toggle() did both.

[code]

<script>
function toggle(hot,id)
{
var a = document.getElementById(id).style.display;
if (a != 'block')
{
document.getElementById(id).style.display = 'block';
hot.innerHTML='[-]';
}
else
{
document.getElementById(id).style.display = 'none';
hot.innerHTML='[+]';
}

}
</script>

<style>
div {
background-color:#C0FFEE;
}

.hidden {
display:none;
background-color:#ABCDEF;
}

#hotstuff{
cursor:pointer;
}
</style>

<div>
<span id="hotstuff" onclick="toggle(this,'secret')">[+]</span> &lt;&mdash; expand this row.
</div>
<div class="hidden" id="secret">
blah<br />blah<br />blah<br />blah<br />blah<br />
</div>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.