I'm setting two local variables inside of a jQuery .load(function(){...})
handler, but I can't find a way to access those variables outside of the handler. I tried removing the var
declaration, but that didn't work. Now I'm trying to use return
, but I can't get it to work either. Instead of alerting a numerical value, Firefox is alerting "[object HTMLImageElement]" when I run the code.
*I can verify that alert(x)
works when placed inside the handler/function.
The code below is a modification of Xavi's solution to reading the actual dimensions of an image.
var imagepopXY = $("<img/>").attr('src', imagepopSrc).load( function() {
var x = this.width;
var y = this.height;
return [x,y]
});
alert (imagepopXY[0]);