ASM wrote on 10 dec 2006 in comp.lang.javas cript:
<button onclick="
var id1 = document.getEle mentById('id1') .style;
var id2 = document.getEle mentById('id2') .style;
if(typeof(asm)= ='undefined') {
// 1st time you press button : hide div 2
// asm is a pointer created at this moment
// to avoid to hide 2nd div at each next pressure
asm = true;
id2.display = 'none';
}
else
{
id1.display = id1.display=='' ? 'none' : '';
id2.display = id2.display=='' ? 'none' : '';
};">hide / show </button>
A global variable remembering the status is not even neccessary:
<script type='text/javascript'>
function swap(button,a,b ) {
var x = document.getEle mentById(a).sty le;
var y = document.getEle mentById(b).sty le;
var swapper = y.display == 'none';
x.display = swapper ? 'none' : '';
y.display = swapper ? '' : 'none';
button.innerHTM L = swapper ?
'hide '+b+' / show '+a :
'hide '+a+' / show '+b;
}
</script>
<button onclick="swap(t his,'id1','id2' )">
hide div id2</button>
<br><br>
<div id='id1'>This is id1</div>
<div id='id2'>This is id2</div>
<br><br>
<button onclick="swap(t his,'id3','id4' )">
hide div id4</button>
<br><br>
<div id='id3'>This is id3</div>
<div id='id4'>This is id4</div>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)