how to show image in javascript code example

Example 1: show image javascript

HTML:
<img id="theImage" src="yourImage.png">
<a id="showImage">Show image</a>

JavaScript:
document.getElementById("showImage").onclick = function() {
    document.getElementById("theImage").style.visibility = "visible";
}

CSS:
#theImage { visibility: hidden; }

Example 2: show image javascript

JS:
function setImageVisible(id, visible) {
    var img = document.getElementById(id);
    img.style.visibility = (visible ? 'visible' : 'hidden');
}

HTML:
<img id="myImageId" src="yourImage.png">
Then, your links would be:
<a href="javascript:setImageVisible('myImageId', true)">show image</a>
<a href="javascript:setImageVisible('myImageId', false)">hide image</a>

CSS:
#theImage { visibility: hidden; }