How can I code a button to copy specific text to clipboard?

How do I code a button that it will copy specific text to the clipboard?

For example:

DISCOUNTCODE

, customer will click on the button, and the

DISCOUNTCODE

will be copied to the user clipboard so he/she can paste it on checkout.