How can I use .each() to get a var, use it, clear it and then start fresh with the next loop of .each()?
I've got a varying number of images with 'title' attribute. I want to take the title attribute and append it to a new div after each image, creating a caption. Using the following code on a page with 2 images, however, I get both of their titles under each image.
How can I run .each() so that it does it's work on the first image, erases it's var, then does it's work on the second image?
jQuery(".node-type-article .imagefield-imagelink img").each( function() {
var caption = jQuery(this).attr('title');
jQuery(this).after('<div class="caption"></div>');
jQuery('.caption').append(caption);
caption = '';
});