javascript - jQuery load() function not setting global variable? -



javascript - jQuery load() function not setting global variable? -

this question has reply here:

why variable unaltered after modify within of function? - asynchronous code reference 6 answers

not sure why figured out here can educate me bit on this. looking set global variable based off jquery loaded object. in case loading original image size server can proportionally resize programatically. stumped why can alert or console log height , width cannot set variable retrieved values outside callback function?

html: <img src='someimage.jpg' /> js/jquery: var imgheight, imgwidth; $("img").load(function() { imgheight = $(this).height(); imgwidth = $(this).width(); console.log(imgwidth + " x " + imgheight); // works }); console.log(imgwidth + " x " + imgheight); // not

is timing issue , improve solution load image , set variable based on response?

this because .load function runs 1 time image has been loaded. console.log outside of load trying log variables have no value.

javascript jquery

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -