My knowledge of JavaScript is quite limited, so I'm unsure about what mistake I might be making.
Here's an example that works perfectly:
myarray = [];
myarray.push(1);
This following example also works flawlessly:
myarray = [];
function example(){
myarray.push(1);
}
example();
However, this next snippet doesn't work at all:
myarray = [];
function example(){
myarray.push(1);
}
$(window).load(function(){
example();
});
I suspect that there might be some scope-related issue with $(window).load(function(){...
.
Is there a way to get example()
to run in the third snippet as it does in the second one?