I'm trying to make a button to select the contents of a <code>
element. However, it's not working and I am getting "content.select()
is not a function
<body>
<div>
<button type="button" id="copyButton" class="btn btn-primary" onclick="copyConfig()">Copy Config</button>
<br><br>
<pre><code id="contentCfg">{{ content }}</code></pre>
</div>
</body>
<script>
function copyConfig() {
const content = document.getElementById("contentCfg").textContent;
content.select();
content.setSelectionRange(0, 99999);
document.execCommand("copy");
}
</script>
No idea why this wouldn't work, {{ content }}
automatically gets filled with text by my template serve.r