How to obtain the width and height of an image using JavaScript

Asked 2 years ago, Updated 2 years ago, 41 views

Is there an API to get dimension of image from JavaScript or jQuery?

javascript jquery image

2022-09-22 16:13

1 Answers

There are clientWidth and clientHeight among DOM properties.

var img = document.getElementById('imageid'); 
//or however you get a handle to the IMG
var width = img.clientWidth;
var height = img.clientHeight;

I think you can write it like this.


2022-09-22 16:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.