How to get image size (height & width) using JavaScript

You can use JavaScript’s clientWidth and clientHeight properties to get the current width and height of an image. These properties will round the value to an integer.

How to get image size (height & width) using JavaScript
<!DOCTYPE html>
  <title>Get image size (height / width) using JavaScript</title>
  <script type="text/javascript">
    function getSize(){
      var img = document.querySelector("#myImg");
      var width = img.clientWidth;
      var height = img.clientHeight;
      alert("Width =" + width + ", " + "Height =" + height);
    <img src="" id="myImg">
    <button type="button" onclick="getSize();">Get image size</button>
Get image size (height / width) using JavaScript

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 *