Javascript Reference - HTML DOM Image height Property








The height attribute specifies the height of an image.

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

Browser Support

height Yes Yes Yes Yes Yes

Syntax

Return the height property.

var v = imageObject.height

Set the height property.

imageObject.height=pixels

Property Values

Value Description
pixels The height in pixels




Return Value

A Number type value representing the height of the image, in pixels.

Example

The following code shows how to change the height of an image to 300px.


<!DOCTYPE html>
<html>
<body>
<img id="myImg" src="http://java2s.com/style/demo/border.png" width="100" height="100">
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--from  ww  w. java  2 s .c o  m-->
    document.getElementById("myImg").height = "300";
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to get the height of an image.


<!DOCTYPE html>
<html>
<body>
<img id="myImg" src="http://java2s.com/style/demo/border.png" width="107" height="98">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<!-- w  w  w .j a v a2 s .co  m-->
<script>
function myFunction() {
    var x = document.getElementById("myImg").height;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: