JavaScript

How to change image size in JavaScript

You can simply use JavaScript’s width and height properties to change the size of your image, as shown in the example below.
 

How to change image size in JavaScript
<html>
  <body>
    <img src="https://via.placeholder.com/300" id="myImg">
    
    <script type="text/javascript">
      var myImg = document.getElementById('myImg');
      
      if(myImg && myImg.style) {
        myImg.style.height = '200px';
        myImg.style.width = '500px';
      }
    </script>
    
  </body>
</html>
Result
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *