More Info


You are in: home > javascript > javascript api >

JavaScript API

Get Image Width/Height - getImageWidth() & getImageHeight()

The functions return the width or height of an image.

NOTE: All the browsers except Netscape 4.x just call getElementWidth(myImage) or getElementHeight(myImage) to get the width or height.

The Code

function getImageWidth(myImage) {
	var x, obj;
	if (document.layers) {
		var img = getImage(myImage);
		return img.width;
	} else {
		return getElementWidth(myImage);
	}
	return -1;
}

function getImageHeight(myImage) {
	var y, obj;
	if (document.layers) {
		var img = getImage(myImage);
		return img.height;
	} else {
		return getElementHeight(myImage);
	}
	return -1;
}
<< PREVIOUS PAGE: Get Element Top/Left NEXT PAGE: Get Image Top/Left >>





 © James Austin 2002-05 Web site design by James Austin