ShowHide HTML Element

A simple function to hide and show an HTML tag.

Introduction

The following snippet exemplifies the element to be show/hidden

<div id="myID" style="display: none;">
Item 1<br>
Item 2<br>
Item 3<br>
</div>

Below, a test link

<a href="#" onClick="showhide('myID')">
<img src="plus.png" border=0 id="myIDimg">ROOT
</a>

And finally, the javascript function

<script language="javascript" type="text/javascript"> 
function showhide(id){ 
    if (document.getElementById){ 
        obj = document.getElementById(id); 
        if (obj.style.display == "none"){ 
            obj.style.display = ""; 
            eval(id + "img.src='minus.png'");
        } else { 
            obj.style.display = "none"; 
            eval(id + "img.src='plus.png'");
        } 
    } 
} 
</script>
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License