I want to get the imagesize in jquery, I have this code. It works to the point of
alert (v);
I wonder what is wrong with the rest when v actually contains a value.
var v = $('#xxx input').val();
alert (v);
var newImg = new Image();
newImg.src = v;
var height = newImg.height;
var width = newImg.width;
alert ('The image size is '+width+'*'+height);
Thanks
Jean
Your code to get the image size won’t always work. The image loads asynchronously, so the height and width will not be available immediately. You’ll need something like the following: