I would like your help and your experience on jQuery.
So, I have a js file. Inside I have defined a object and then i use the document.ready(). Inside .ready() function i call a function, which is create some divs elements and it is defined after .ready(). The code looks like this:
gridObject = {};
document.ready(function() {
createElements();
console.log(gridObject);
});
function createElements() {
var htmlBuffer = "<div class='test'>Content 1</div>" +
"<div class='test'>Content 2</div>";
$('.container').html(htmlBuffer);
gridObject = getGrid();
console.log(gridObject);
}
function getGrid() {
return $('.test');
}
When i run this code the elements have been created, but the first console.log(gridObject) is emty, while the console.log() within createElements() return the elements. Also if i type the gridObject in Console Inspector, it returns me the object as it should...
So how this happens? Can anyone explain to me step by step how commands run and the first console return empty object, as result? And how can i deal with it?
Thank you for your time to read and answer these questions!