Javascript DOM HTML Image height and width set

Introduction

Change the height and width of an image to 200px:

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

View in separate window

<!DOCTYPE html>
<html>
<body>

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

<script>
function myFunction() {// w w w .  jav a2  s  .  c  o  m
  document.getElementById("myImg").height = "200";
  document.getElementById("myImg").width = "200";
}
</script>

</body>
</html>



PreviousNext

Related