I'm appending an image with jQuery and i can't get the sizes (width and height) of it.
Here it is the HTML code:
<input type="checkbox" id="RocketElement" data-id="1">
Here it it is the JS/jQuery code:
$(document).ready(function() {
function printOne(newData) {
var deferred = $.Deferred();
$("#Images").append("<img data-id='" + newData.attr("data-id") + "' src='file:///C:/Users/David/Documents/test/" + newData.attr("data-id") + ".png'>");
deferred.resolve();
return deferred.promise();
}
function getSizes(newData) {
console.log($("img[data-id='" + newData.attr("data-id") + "']").width());
}
$("input#RocketElement").on("change", function() {
Data = $(this);
printOne(Data).done(function() {
getSizes(Data);
});
});
});
However, when i add a delay after the .append of 10ms it works. Is there any way to wait until the DOM has been updated and then continue with the execution of the code?