Image height Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image

Description

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

Set the height property with the following Values

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

Return Value

A Number, representing the height of the image, in pixels

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<img id="myImg" src="http://java2s.com/resources/a.png" width="107" height="98">

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {//from   w ww .  j  a  va 2s. c  om
    document.getElementById("myImg").height = "300";
}
</script>

</body>
</html>

Related Tutorials