The alert works, but the return is 0. How do I get it to return the correct value?
var img;
img = new Image();
img.onload = function() {
alert(img.width);
return(img.width);
};
img.src = "https://maps.gstatic.com/mapfiles/dir/bike.png";
alert(img.width);
onloadwill be executed at an arbitrary point in the future: do what you need to do in the onload function itself.img.widthto? The more information you give, the better you can be helped.