I'm trying to copy text to clipboard that is inside a h3 tag. I get the following error at the copyText.select() code line.
Uncaught TypeError: copyText.select is not a function at HTMLDivElement.
edit: When using on a input-tag the copy to clipboard function works, but not when inside h3 tag.
HTML
<div class="colorDiv" id="firstColorObject">
<h3 class="colorCode" id="p1" value="123">#Color 1</h3>
</div>
JavaScript
document.querySelector("#firstColorObject").addEventListener("click", function(){
var copyText = document.getElementById("p1");
copyText.select();
document.execCommand("copy");
alert("Copied the text: " + copyText.value);
}, false);