Javascript DOM HTML Image height Property set

Introduction

Change the height of an image to 200px:

document.getElementById("myImg").height = "200";

Click the button to change the height of the image to 200px.

View in separate window

<!DOCTYPE html>
<html>
<body>

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

<script>
function myFunction() {/*from   w  ww  .  java  2  s . com*/
  document.getElementById("myImg").height = "200";
}
</script>

</body>
</html>

The height property sets or gets the value of the height attribute of an image.

The height attribute specifies the height of an image.

The height property can return the height of an image that has been styled with CSS.

Value Description
pixels The height in pixels (e.g. height="100")

The height property returns a Number representing the height of the image, in pixels.




PreviousNext

Related