Get image size when it loads from an extern URL in Javascript
I need to know the image size when it loads from an extern URL because the project needs to resize the image div. I need to do something like this: <img id="imglegend'+layername+'" src="url_to_an_extern_host" /> And, using Javascript and JQuery: $('#imglegend'+layername).ready(function(){ var h = $('#imglegend'+layername); // Resize image div container }); But this didn't work. Is it possible to do? Thanks in advance! $('#imglegend').load(function(){ var w = $(this).width(); var h = $(this).height(); alert(w); alert(h); }).error(function (){ $(this).remove();//remove image if it fails to load/