I am using .each() to iterate over the links in the jQuery object $firstParagraph. As I iterate over the links, I would like to refer to them in an absolute way, without calling $(this) which creates a new object each time it is called. Because when I iterate twice independently over the links (as shown in the code below), then the work done in both instances is not combined.
$firstParagraph = $("p").eq(0);
// Iterate over the links once
$firstParagraph.find("a").each( function()
{
$this = $(this);
// Modify $this
});
// Iterate over the links a second time
$firstParagraph.find("a").each( function()
{
$this = $(this);
// I want to modify $this again, but without loosing
// the work I did in the first iteration
});
Instead of going violently against the grain of jQuery like you’re asking, let me advise you how to do what you actually need to do: use
$(this).data('somekey', someval)and$(this).data('somekey')to, instead of directly modifying$(this)as an object and so losing whatever you’re trying to do, attach data to your concept of$(this)in such a way that you’ll be able to get it back. (Docs here.)