Javascript DOM CSS Style visibility Property hide and show image element

Introduction

Hide and show an <img> element:

View in separate window

<!DOCTYPE html>
<html>
<body>

<img id="myImg" src="image1.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() {/* ww  w.  j  ava2 s . c o m*/
  document.getElementById("myImg").style.visibility = "hidden";
}

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

</body>
</html>



PreviousNext

Related