Change the width and height of an <img> element: - Javascript CSS Style Property

Javascript examples for CSS Style Property:width

Description

Change the width and height of an <img> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<img id="myImg" src="http://java2s.com/resources/c.png" width="100" height="132">
<br>

<button type="button" onclick="myFunction()">Change height and width of image</button>

<script>
function myFunction() {//from   w  w  w  .j  ava  2  s .c  om
    document.getElementById("myImg").style.height = "300px";
    document.getElementById("myImg").style.width = "300px";
}
</script>

</body>
</html>

Related Tutorials