js code for copy to clipboard selected text code example
Example 1: js copy text to clipboard
function copy() {
var copyText = document.querySelector("#input");
copyText.select();
document.execCommand("copy");
}
document.querySelector("#copy").addEventListener("click", copy);
Example 2: copy to clipboard javascript dom
navigator.clipboard.writeText('Text');