copy text in html code example
Example 1: copy text to clipboard javascript
<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>
Example 2: jquery copy to clipboard
document.execCommand("copy");