Root: WRM Database > Information Technology > Programming Languages > JavaScript > Showing and Hiding Divs > Showing a Div Using Javascript



Showing A Div Using JavaScript


Click the plus sign
This hides/shows your div



Here's how the code looks:

<div id="container">
<div id="top_div">Click the plus sign</div>
<a id="plus_minus_image" href="javascript:toggle('bottom_div', 'plus_minus_image');"><img src="../images/node_middle_plus.gif"></a>
</div>

<div id="bottom_div" style="display: block;">This hides/shows your div</div>



<script type = "text/javascript">
function toggle(showHideDiv, switchImgTag) {
var ele = document.getElementById(showHideDiv);
var imageEle = document.getElementById(switchImgTag);
if(ele.style.display == "block") {
ele.style.display = "none";
imageEle.innerHTML = '<img src="../images/node_middle_plus.gif">';
}
else {
ele.style.display = "block";
imageEle.innerHTML = '<img src="../images/node_middle_plus.gif">';
}
}
</script>