Based on the answer I received here, it seems I need a closure to get this code working correctly. Unfortunately, despite the links provided, I am still confused as to how a closure should be implemented in my case, so when a specific image is clicked a specific URL unique to that image is opened. (Currently, I am just getting an "undefined" because, as Pointy said, 'the value of "i" will be links.length'.)
In a nutshell, how do I "carry" the number/index of "i" over to "window.location.replace(pages[]);", and if a closure is indeed correct in this case, how would I make use of one?
Hate to keep bothering people but I don't think I can figure this out on my own. Thanks.
Original code:
var links = ["#portfolio", "#animations", "#games"];
var pages = ["http://www.gog.com", "http://www.google.com", "http://www.hamumu.com"];
$(function() {
for (var i=0; i<links.length; i++) {
//for (var e=0; e<pages.length; e++) {
$(links[i]).click(function() {
window.location.replace(pages[i]);
});
//}
}
});