Measuring Image Widths in JavaScript (Carefully!)


Let’s say you want to find an <img> on the page and find out how wide it is in JavaScript. Maybe you need to make some choices based on that width (or height, or both) You can definitely do that. The DOM will even give you a variety of dimensions to choose from depending on what you need. There is definitely a catch though.

Here’s the image:

<img src="http://css-tricks.com/image.jpg" alt="an image">

And here’s us selecting it, by finding the first <img>

Read the entire article at the source link…


We're happy to share this resource that we found. The content displayed on this page is property of it's original author and/or their organization.

Leave a Reply