How can I access the value of imgWidth
? This is giving me undefined
.
somejQueryMethod(function() {
var imgWidth;
$("<img/>").attr(
"src",
$("#SomeImgSelector").attr("src")
).load(function() {
imgWidth = this.width;
});
// use imgWidth here
// imgWidth is undefined here
});
Background info: From this SO question I assumed that as
imgWidth
was being defined outside of theload()
method, it would always be available outside ofload()
. Which makes me wonder why defineimageWidth
there and not inload()
?