I am trying to select a <p>
element with the function .select()
.
I know that you can select text inside an input element, but I have not found a way to select text from other elements.
I have tried document.getElementById()
, but it doesn't seem to work.
<p id='test'>Text to select.</p>
<button onclick='copy()'>Click</button>
function copy() {
var x = document.getElementById('test');
x.select();
document.execCommand('copy');
}
I then receive an error message that says 'x.select is not a function.'.