There are a few simple ways:

(1) use https://clipboardjs.com/ . Add the content to be copied to clipboard to an attribute "data-clipboard-target".

(2) if you are using Wordpress, check the Wordpress Plugins:
* Copy Anything to Clipboard : https://wordpress.com/plugins/copy-the-code
* Copy Code To Clipboard : https://wordpress.com/plugins/copy-code-to-clipboard