The function above requires two parameters. The first one is the name of the close/open image. The second parameter is the name of the element we want to hide or show. The function checks the state of the element, and changes the state. In other words, the function shows a hidden section and hides a displayed section, thanks to the if/else conditional statement. The function also changes the image source for the item we are planning to click on. The open.png and close.png files could either be arrows or plus/minus signs.
<img src="open.png" id="myimage1" onclick="ToggleVisibility('myimage1','mydiv1')"> <div id="mydiv1"> <p> This is the paragraph that will be hidden or displayed when we click the image. </p> </div>