Copy text directly to clipboard in

I want the value I clicked on the event to be saved in the clipboard but this code does not work please see where my mistake is

<button class="btn btn-outline-warning" onclick="navigator.clipboard.writeText(@Model.projectCode)">@Model.projectCode</button>


You can use function below to copy element in clipboard

<button class="btn btn-outline-warning" onclick="copyToClipboard('@Model.projectCode')">@Model.projectCode</button>

function copyToClipboard(element) {
     var $temp = $("<input>");