I'm having a few issues and I think it is because of the way I'm declaring an array. I'm using jQuery and I want to declare a global array so I can use its items inside my functions. The way I'm doing it now, when I do try to use the items in a function, they are limited. I did a console log of the array and it seems to show that it has stuff in it (even the stuff that I want) but then when I perform jQuery functions on those items it tells me
Cannot read property 'top' of undefined
Additionally, I've not used arrays much in JS, just in C++, so perhaps there's an issue with my syntax? Here is a rough copy of the code I have:
var pigs = new Array();
pigs[0] = $('#foo');
pigs[1] = $('#bar');
$(document).ready(function(){
console.log(pigs);
var topCoord = pigs[0].offset().top;
});
$('#foo')wont return an element beforedocument.ready