Successfully got it to work, although not the most efficient method, it does the trick.
I have a webpage filled with links (). In addition, there is an empty div at the bottom named .
The script loads an icon next to these links. When clicked, the links direct to new pages displaying multiple images. The icons are compact versions of the standard images on those pages.
function handleIconPics(){
var linkTags = $('#linkpage a');
for(var i = 0; i < linkTags.length; i++){
$('#invisible').load('page3.html #standardImage',function(aTag){
return function(){
$('<img src="'+ $('#standardImage').attr("href") +'" />')
.prependTo(aTag);
}
}
($(linkTags[i])));
}
$('#invisible').hide();
}
Initially, I gather all the links within the linkpage. This sets up the remainder of the code within a for-loop to apply the same actions to all links.
Subsequently, I load "#standardImage" from page3.html into "#invisible". "#standardImage" acts as an empty div containing a URL leading to a condensed version of page3's standard image, stored within the div's href attribute.
Then came the challenging part. I implemented a callback function where I constructed a function accepting one argument designated at the end($(linkTags[i])). This function then yields a new function! This allows me to access both the linkTags (links) and the newly loaded $('#standardImage').
Within the function, I extract the href from $('#standardImage') and utilize it as the src for an image that is prepended to the link.
Lastly, outside the for-loop, I hide $('#invisible').
Admittedly, this may not be the most sophisticated approach, but it serves its purpose. Who knows, it might assist the next beginner facing a similar dilemma.