Javascript DOM HTML Image height Property get

Introduction

Return the height of an image:

var x = document.getElementById("myImg").height;

Click the button to display the height of the image.

View in separate window

<!DOCTYPE html>
<html>
<body>

<img id="myImg" src="image1.png" width="100" height="98">
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from   w w w  .  ja  v  a 2s  . c om*/
  var x = document.getElementById("myImg").height;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related