I need to create a function that gets the url from one link and applies it to another within the same div. I can get it to loop through but it always assigns the last variable to all of the links.

Here is the code :

```
$.fn.getLink = function() { 

    $('a.firstlink').each(function(){

         var linkHref= $(this).attr('href');

         ('a.secondlink').attr('href', linkHref)

    });

}

$('div.containing-links').each(function(){

    $(this).getLink();

});

```

Help appreciated.

Thanks for your quick answers, to make it a bit simpler here is the code that adds the link correctly **but repeats the last href variable** to all of them:

$('a.firstlink').each(function(){

```
var linkHref= $(this).attr('href');

$('a.secondlink').attr('href', linkHref);

    });

```

How can I apply this to **each one at a time?**