Javascript DOM HTML Image height Property styled with CSS

Introduction

Return the height of an image that has been styled with CSS:

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

Click the button to return the height of the image.

View in separate window

<!DOCTYPE html>
<html>
<body>

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

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

<script>
function myFunction() {//from www. jav  a2 s . c  o m
  var x = document.getElementById("myImg").height;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related