I'm loading the source of an image dynamically using ajax, where s is this source. I create an image element in the DOM, assign it this source once it's loaded, and then append it to a div called imgwrapper. Then I try to get the image's dimensions, but it doesn't work. I'm aware you can't get the dimensions of an image that's dynamically loaded, but not even after being appended to the DOM?
My code is as below:
//use ajax to get value of s (the image source)
img = document.createElement("img");
img.src = s;
$('#imgwrapper').appendChild(img);
console.log($('#imgwrapper').find('img').width());
this returns 0, instead of giving me the image's width.
$.appendChild(), that should be$.append(). On another note, you don't need to reselect the element after it's appended, you can just wrapimgin a jQuery object:$(img).width().