jquery - Dimensions of an uploaded image -
i need dimensions of user uploaded image is, there file upload button loads image 'img' tag , depending on size of img, img element attributes set. essentially, upon page load, image tag much this:
<img id="img"> when user uploads image of dimensions 222 x 227, dimensions rendered are:
<img id="img" width="222" height="227"> <!--verified inspecting element --> i want retrieve dimensions of uploaded image , using jquery, script:
$('#img').attr('width') or $('#img').attr('height'); return 'undefined'. also, $('#img').attr('src') returns undefined though upon inspecting element in fact show these attributes loaded right values.
this makes me conclude image uploaded not added dom perhaps?
anybody know what's ?
ok, figured out what's up, doing helped:
$('#img').load(function(){ console.log($('#img').attr('width')); }); gives me dimension want. however, have no thought why needed load() function callback here, if wants shed lite on it.
jquery image dom
No comments:
Post a Comment