[jQuery] .click with confirm coming up multiple times

[jQuery] .click with confirm coming up multiple times


I have been working on a script, that will put a URL into a var when a
link is clicked. Then, when a second link is clicked a confirm dialog
appears, if you click ok, that var is printed.
Problem is, it works only the first time you click one of the first
links. If you click a second link, and then the link that activates
the confirm, it throws 2 confirm dialogs, one for the first link, and
one for the second link. How can I make the var get overwritten each
time a new link is clicked?
$("a.test").click(function() {
var location = $(this).attr("rel");
$("#test2").click(function() {
var answer = confirm("Are you sure you want to delete this
asset?");
     if (answer) { $("#textTest").text(location); }
});
    });
<a class="test" rel="http://www.microsoft.com" href="#">Remove</a> <a
class="test" rel="http://www.apple.com" href="#">Remove</a> <a
id="test2" href="#">Add</a>
<div id="textTest"></div>