$(document).ready(function() {
var totalTitles = "";
function getSubtitles() {
for(var i=0; i<currentArray.length; i+=2) {
totalTitles += "<li><a href='" + currentArray[i+1] + "'>" + currentArray[i] + "</a></li>";
}
alert(totalTitles);
}
$("#menu-header .mainTitles").click(function() {
getSubtitles();
});
alert(totalTitles);
});
I can load the totalTitles
variable in a for
loop. However, when the for
loop is finished, the totalTitles
variable has the default value of " "
.