Hide and show an <img> element: - Javascript CSS Style Property

Javascript examples for CSS Style Property:visibility

Description

Hide and show an <img> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<img id="myImg" src="http://java2s.com/resources/c.png" width="100" height="132">
<br>

<button type="button" onclick="hideElem()">Hide image</button>
<button type="button" onclick="showElem()">Show image</button>

<script>
function hideElem() {//  w w  w .java2s  .  c  o  m
    document.getElementById("myImg").style.visibility = "hidden";
}

function showElem() {
    document.getElementById("myImg").style.visibility = "visible";
}
</script>

</body>
</html>

Related Tutorials