how would i get a image width using only the image link in jquery? can someone lead me down the right path please
Thank You,
how would i get a image width using only the image link in jquery? can someone lead me down the right path please
Thank You,
var img = new Image();
img.src = "http://your.host.here/your.image.file.png";
img.onload = function() {
alert(this.width);
};
You can do this using JavaScript, but only in an asynchronous manner, because the image would need to be downloaded before you could access its width:
function getImgSize(src, callback) {
var img = new Image();
img.src = src;
img.onload = function () { callback(this.width, this.height); }
}
Example usage
getImgSize("http://www.google.co.uk/logos/classicplus.png", function (w, h) {
alert(w);
});