//As simple as this
navigator.clipboard.writeText("Hello World");
navigator.clipboard.writeText('Lorem Ipsum')
<html>
<input type="text" value="Hello world"(Can be of your choice) id="myInput"(id is the name of the text, you can change it later)
<button onclick="Hello()">Copy Text</button>
<script>
function Hello() {
var copyText = document.getElementById('myInput')
copyText.select();
document.execCommand('copy')
console.log('Copied Text')
}
</script>
const copyOnClipboard = (txt) => navigator.clipboard.writeText(txt)
<script>
function copyToClipboard(element) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(element).text()).select();
document.execCommand("copy");
$temp.remove();
}
</script>
<p id="text">Hello</p>
<button onclick="copyToClipboard('#text')"></button>
navigator.clipboard.writeText("your text here")
// promise is returned for outcome;
// might require browser permissions;
// prefer this API as "execCommand" is deprecated
navigator.clipboard.writeText("some text").then(function() {
/* clipboard successfully set */
}, function() {
/* clipboard write failed */
});