The height
attribute specifies the height of an image.
The height
property sets or gets the value of the height attribute of an image.
height |
Yes | Yes | Yes | Yes | Yes |
Return the height property.
var v = imageObject.height
Set the height property.
imageObject.height=pixels
Value | Description |
---|---|
pixels | The height in pixels |
A Number type value representing the height of the image, in pixels.
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:
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: