I am looking for a way to copy the text inside of a header on my website to the users clipboard. I am a beginner at HTML and JS, so I am struggling quite a bit. This is what I have so far:
<!DOCTYPE html>
<html>
<body>
<h2>Test<h2 id="ip">
<button onclick="copyToClipboard()">Copy To Clipboard</button>
<script>
function copyToClipboard() {
var copyText = document.getElementById("ip")
copyText.select();
document.execCommand("copy");
}
</script>
</body>
</html>
This script does not copy the header and I cannot figure out why. This is the error I get: Uncaught TypeError: copyText.select is not a function
Any help would be appreciated.
Test
– j08691 Jul 07 '19 at 19:45` Is invalid HTML