You can increase or decrease the size of an image using JavaScript by manipulating the width and height properties of the image element.

To increase the size of the image, you can use the width and height properties to set the new dimensions of the image. For example:

var img = document.getElementById("myImage");
img.width += 50;
img.height += 50;

To decrease the size of the image, you can use the width and height properties to set the new dimensions of the image. For example:

var img = document.getElementById("myImage");
img.width -= 50;
img.height -= 50;

You can also use a variable to store the original width and height of the image, so that you can easily change the size of the image by a certain percentage.

var img = document.getElementById("myImage");
var originalWidth = img.width;
var originalHeight = img.height;
// Increase the size by 50%
img.width = originalWidth * 1.5;
img.height = originalHeight * 1.5;
// Decrease the size by 50%
img.width = originalWidth * 0.5;
img.height = originalHeight * 0.5;

Please note that changing the size of the image using these methods will only change the display size of the image, it will not change the actual image file.

Also Read:

Categorized in: