Change image size with JavaScript

Once you have a reference to your image, you can set its height and width like so:

var yourImg = document.getElementById('yourImgId');
if(yourImg && yourImg.style) {
    yourImg.style.height="100px";
    yourImg.style.width="200px";
}

In the html, it would look like this:

<img src="https://stackoverflow.com/questions/1297449/src/to/your/img.jpg" id="yourImgId" alt="alt tags are key!"/>

Leave a Comment