I have the following working code:
// Get photos from file and load first initial photo
$.ajax({
type: "GET",
url: "photos_gps.json",
success: initialPhoto,
error: handleError
});
function initialPhoto(data){
console.log(data);
var img_tag = "<img id=" + '"photoBox" src=' + "'photos/" + data[0].Filename + "' />";
console.log("Img_tag: " + img_tag);
$('#mainBox').prepend(img_tag);
photos = data;
setTimeout(function() {
console.log($('#photoBox').height());
console.log($('#photoBox').width());
}, 1000);
}
First I'm loading a file which contains information about images. After succes I choose the first image and prepend this to the DOM element. When I log the width and height of the image without the setTimeOut function the values will be both 0 and with setTimeOut function 3648 and 5472.
I want to get rid of the setTimeOut function so I've tried the following callback function:
$('#mainBox').prepend(img_tag, function() {
console.log($('#photoBox').height());
console.log($('#photoBox').width());
});
This results into the following text added below the image:
function() { console.log($('#photoBox').height()); console.log($('#photoBox').width()); }
Looks like I don't understand callbacks yet...