Let's say you want to find an
Here's the image:
<img src="image.jpg" alt="an image">
And here's us selecting it, by finding the first
var img = document.querySelector("img");
Let's just log the width:
... read the whole story at css-tricks.com.
// How wide the image is rendered at (which could be affected by styles) console.log(img.width); // How wide the image itself actually is console.log(img.naturalWidth); // There is also `offsetWidth` (width with border and padding) and `clientWidth` (width with just padding) // Those aren't usually too useful with images