Is there a way to "save" a variable in jQuery?
I have an .each() loop that changes the value of sz[1] and fires a .load() for each value. However, when I place sz[1] in the callback function, it only uses the last recorded value of sz[1], and not the value it had when I initially called .load().
$("#Big").find("a").each(function() {
url = $(this).attr("href");
pattern = new RegExp("sizes/([" + sizes + "])/$");
otherPattern = new RegExp("sizes/([" + otherSizes + "])/$");
sz = pattern.exec(url);
if(sz) {
normLink(sz[1], srcBase);
} else {
sz = otherPattern.exec(url);
if(sz) {
NotOkToDeLoad++;
$("a#" + sz[1]).load(URL + sz[1] + " div#psp", function() { fixLink(sz[1]); });
}
}
});
sz[1] can be "k", "h" or "o". However, fixLink() is always called with that last possible value of "o" three times.
My current workaround is to write three separate .load()'s for each possible value of sz[1], but there ought to be an easier way. Am I overlooking something?