workforchange() - a simple show/hide javascript
Destroy p1
I am P1! I go away!
<script type="text/javascript">
<!--
function showhide(targetID) {
//change target element mode
var elementmode = document.getElementById(targetID).style;
elementmode.display = (!elementmode.display) ? 'none' : '';
}
function changetext(changee,oldText,newText) {
//changes text in source element
var elementToChange = document.getElementById(changee);
elementToChange.innerHTML = (elementToChange.innerHTML == oldText) ? newText : oldText;
}
function workforchange(targetID,sourceID,oldContent,newContent) {
showhide(targetID);
changetext(sourceID,oldContent,newContent);
}
// Cruft note: The content of "oldContent," the third argument of the
// workforchange() function, must match the existing content of the changer text.
// -->
</script>
<a href="javascript:workforchange('p1','changer','Destroy p1','Restore p1');" id='changer'>Destroy p1</a>
<span id='p1'>I am P1! I go away!</span>
<a href="javascript:workforchange('p2','changer2','Summon p2','Destroy p2');" id='changer2'>Summon p2</a>
<span id='p2' style='display:none'>I am P2! I have appeared!</span>