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


Are there any JavaScript or jQuery APIs or methods to get the dimensions of an image on the page?

Best Solution

You can programmatically get the image and check the dimensions using Javascript...

const img = new Image();
img.onload = function() {
  alert(this.width + 'x' + this.height);
img.src = '';

This can be useful if the image is not a part of the markup.