I’m storing information about links in an array. I want to be able to reference the links later through jQuery. How do I save the reference to each link as part of the information associated with the element? When I define reference: $(this), then reference always refers to the very last link in the for loop for every link (i.e. some type of problem with references).
var linkInfo = new Array();
$("a").each(function(index, elt) {
var currentInfo = {};
currentInfo.i = index;
// Gather info about the <a> tag
currentInfo.link = {
reference: $(this), // todo fix this reference: info.link.reference yields last object
offset: $(this).offset(),
}
}
you mean like: