How to get the id and paste it in the link?

For example, there is a link

<a href="#" class="button" id="123"></a>

How to get the id value and paste into another link, to get something like this:

<a href="#buy=123"></a>
June 26th 19 at 14:19
2 answers
June 26th 19 at 14:21
June 26th 19 at 14:23
the second button to choose the class or at your option
$('selector here').attr('href', '#buy='+$('.button').attr('id'))

Find more questions by tags jQuery