navigator.clipboard.writeText('the text')
<input type="text" placeholder="Create Password" id="text" readonly>
<script>
function copyPassword(){
var copyText = document.getElementById('text')
copyText.select()
copyText.setSelectionRange(0, 999)
document.execCommand("copy")
console.log(copyText);
}
</script>
function copyToClipboard(element) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(element).text()).select();
document.execCommand("copy");
$temp.remove();
}