I want to create some elements of a particular number, inside a loop, store them in a variable, then access that variable outside that loop.
The reason I want to access that variable outside the loop is so that I can put them inside an append function.
function range(start, stop, step) {
var a = [start],
b = start;
while (b < stop) {
b += step;
a.push(b);
}
return a;
}
var yAxis = range(1, 100, 10);
$.createAxis = function(axisValues) {
$(axisValues).each(function(index, element) {
yAxisNav = document.createElement('div');
var newValue = document.createTextNode("I have content!");
yAxisNav.appendChild(newValue);
return yAxisNav.className = 'graphBar_yAxis_label';
});
}(yAxis);
console.log(yAxisNav);
//$('body').append('<section>'+yAxisNav+'</section>');
The above only returns one element, how can I store this so that its accessible outside that loop?