I have three icon images in the title. They consist of a camera, a bicycle and a child. I want to hide / show the corresponding images in the body depending on which icon is clicked. The previous image should be hidden when you click the next icon. I would also like the default value on the page to be "hidden".
I also want to click the icon once to show the image, and again to hide again.
CSS
img { margin: 15px; } .camera { display: none; } .bike { display: none; } .baby { display: none; }
Javascript
var _hidediv = null; function showdiv(id) { if (_hidediv) _hidediv(); var div = document.getElementById(id); div.style.display = 'block'; _hidediv = function () { div.style.display = 'none'; }; }
HTML
<a onclick="showdiv('camera');"> <img src="camera.png" /> </a> <a onclick="showdiv('bike');"> <img src="bike.png" /> <a onclick="showdiv('baby');"> <img src="baby.png" /> <div id="camera" style="display: none;"> <img src="camera1.jpg" /> </div> <div id="bike" style="display: none;"> <img src="bike1.jpg" /> </div> <div id="baby" style="display: none;"> <img src="baby1.jpg" /> </div>
source share