execCommand()function used to build Copy to Clipboard functionality. This Dom function executes a specific command to copy a particular document.
We also use the copy command with the document.execCommand() to copy the text to the clipboard.
On the below example, we will show you the functionality copy to clipboard with source code.
The following code snippet copies the text to the clipboard by using execCommand().
<input type="text" id="userInput" value="Welcome to PHPCODER">
<button onclick="copyText()">Copy text to Clipboard</button>
var text = document.getElementById("userInput");
alert("Copy text to Clipboard: " + text.value);
To know more, HTML DOM execCommand() Method (w3schools.com)